Joe Phillips
Joe Phillips

Reputation: 51160

MailAddress in .NET

I'm attempting to send an email and instead of sending 5 individual emails to each person, I would like to send one mass email to all 5 people. The difference here is that I want everyone to show up in the "TO" or "CC" lines. How can I do this?

Upvotes: 1

Views: 1841

Answers (3)

Scott Arrington
Scott Arrington

Reputation: 12503

using System.Net.Mail;

...

MailMessage mmsg = new MailMessage();
mmsg.To.Add(new MailAddress("[email protected]"));
mmsg.To.Add(new MailAddress("[email protected]"));
mmsg.To.Add(new MailAddress("[email protected]"));

// set other properties here...

SmtpClient client = new SmtpClient("mymailserver.com");
client.Send(mmsg);

Edit: aww, john's fingers are faster than mine ;)

Upvotes: 3

Lloyd
Lloyd

Reputation: 29668

MailMessage.CC.Add(new MailAddress(address))

Check out: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.cc.aspx

Upvotes: 2

John Sheehan
John Sheehan

Reputation: 78132

This will send only one message:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("[email protected]", "Optional Name"));
msg.To.Add(new MailAddress("[email protected]"));
msg.To.Add(new MailAddress("[email protected]"));
msg.CC.Add(new MailAddress("[email protected]"));
msg.CC.Add(new MailAddress("[email protected]"));

// can add to BCC too
// msg.Bcc.Add(new MailAddress("[email protected]"));

msg.Body = "...";
msg.Subject = "...";

SmtpClient smtp = new SmtpClient();
smtp.Send(msg);

Upvotes: 6

Related Questions