CaioVJesus89
CaioVJesus89

Reputation: 333

Not sends email to more than one address

I have an problema to send more than one email in my web app. If I send to just one address, it send normally!

My string list is correct, because if I paste in Outlook and send manualy, all adressess receives.

Well, it's my string listEmail have a value "[email protected]", I received. If string listEmail have value "[email protected]; [email protected]; [email protected];" nobody receives.

lstEmail.ToList();
        string listEmail = string.Join("; ", lstEmail.ToArray());

System.Net.Mail.MailMessage objEmail = new System.Net.Mail.MailMessage();
        objEmail.From = new MailAddress("[email protected]", "BR");
        objEmail.To.Add(listEmail);
        objEmail.Priority = System.Net.Mail.MailPriority.High;
        objEmail.IsBodyHtml = true;
        objEmail.Subject = "System NDRSecurity - Novas Requisições.";
        objEmail.Body = "EX";
        objEmail.SubjectEncoding = Encoding.GetEncoding("ISO-8859-1");
        objEmail.BodyEncoding = Encoding.GetEncoding("ISO-8859-1");
        SmtpClient objSmtp = new SmtpClient("XXX");
        objSmtp.EnableSsl = true;
        objSmtp.Port = 25;
        objSmtp.Credentials = new NetworkCredential("[email protected]", "XXX");
        objSmtp.Send(objEmail);

Upvotes: 0

Views: 201

Answers (2)

Harrison Paine
Harrison Paine

Reputation: 611

Your listemail string needs to be separated by a comma ,, not a semicolon ;.

Here's the MSDN article explaining the MailAddress class: http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx

Upvotes: 1

Pilgerstorfer Franz
Pilgerstorfer Franz

Reputation: 8359

See MSDN MailAddressCollection for solution

Parameters

addresses

Type: System.String

The e-mail addresses to add to the MailAddressCollection. Multiple e-mail addresses must be separated with a comma character (",").

So change your code to

lstEmail.ToList();
string listEmail = string.Join(", ", lstEmail.ToArray());

and it should work!

Upvotes: 6

Related Questions