How do I send an email to an Exchange Distribution list using c#
Asked Answered
P

5

8

I need to send an email to an Exchange distribution list called "DL-IT" using c#.

Does anyone know how to achieve this?

Presley answered 27/5, 2009 at 14:49 Comment(0)
M
8

The simplest way would be to find the actual email address of the DL, and use that in your "To:" field. Exchange distribution lists actually have their own email addresses, so this should work fine.

Monnet answered 27/5, 2009 at 14:53 Comment(1)
what if i want to remove the distribution list email address from an email massage, and sent it to the individual list members? i have more details in my question in here : #37729007Raasch
A
3

Exchange server runs SMTP so one can use the SmtpClient to send an email.

One can lookup the SMTP address of the distribution list (manually) and use that as the "to" address on the MailMessage constructor. The constructor call will fail if you just pass in the name of the distribution list as it doesn't look like a real email address.

public void Send(string server, string from, string to)
{
    // Client to Exchange server
    SmtpClient client = new SmtpClient(server);

    // Message
    MailMessage message = new MailMessage(from, to);
    message.Body = "This is a test e-mail message sent by an application. ";
    message.Subject = "test message 1";

    // Credentials are necessary if the server requires the client 
    // to authenticate before it will send e-mail on the client's behalf.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    // Send
    client.Send(message);
}
Authoritarian answered 27/5, 2009 at 15:3 Comment(1)
Will Exchange actually do a lookup like that on a DL name sent via SMTP? I was under the impression that it didn't.Monnet
A
2

Basically you need to combine two solutions above.

Using code snippet from Scott solution - you should send to [email protected].

But exchange name alias is not always the same as group e-mail, so

  • you may open an empty e-mail in Outlook with DL-IT in To field
  • double-click the DL-IT in To field
  • copy value from Alias Name field and add @mycompany.com.
Affra answered 8/2, 2011 at 17:14 Comment(0)
B
0

The above answers are fine, just be aware that if one of the members of the of the distribution list is not a valid address, the SMTP server may reject the entire Email message as being undeliverable.

This may be because in our case we are using an SMTP server that is not part of Exchange, but never the less it's something to be aware of.

Burnley answered 17/9, 2011 at 5:12 Comment(0)
R
0

In my case it wasn't working because I sent the email to one of multiple aliases that were defined for this list. It seems to me like the address that is used for display may be different than the real address.

The way I got it to work was in Outlook (2016) to click on the "To..." button, then in the global address book search for the ML. There were two entries, one with a globe symbol, one with a people symbol.

enter image description here

Right click the one with the globe, select Properties. Here you can find the email address.

Repudiate answered 13/11, 2019 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.