Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send email to multiple address using System.Net.Mail

Tags:

c#

.net

smtp

I have smtp email functionality. it works for single address but has problem in multiple address.

i am passing multiple addresses using following line of code.

MailAddress to = new MailAddress("[email protected],[email protected]"); 

Please let me know the problem as i am not getting any error.

like image 780
Denish Avatar asked Sep 21 '11 11:09

Denish


People also ask

How do I send to multiple email addresses in SMTP?

In short, to send to multiple recipients you should set the header to be a string of comma delimited email addresses. The sendmail() parameter to_addrs however should be a list of email addresses.

Can emails be sent to multiple addresses?

If you're sending an email to multiple recipients who don't need to know each other's email address, use Blind Carbon Copy (Bcc) instead of Carbon Copy (Cc). Click Bcc / Show Bcc - A Bcc field will appear in each new message. Enter addresses into the Bcc field to avoid other recipients seeing them.


1 Answers

MailMessage msg = new MailMessage(); msg.Body = ....; msg.To.Add(...); msg.To.Add(...);  SmtpClient smtp = new SmtpClient(); smtp.Send(msg); 

To is a MailAddressCollection, so you can add how many addresses you need.

If you need a display name, try this:

MailAddress to = new MailAddress(     String.Format("{0} <{1}>",display_name, address)); 
like image 97
Marco Avatar answered Sep 18 '22 18:09

Marco