0

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 "caio.jesus@ex.com", I received. If string listEmail have value "caio.jesus@ex.com; raul@ex.com; mat@ex.com;" nobody receives.

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

System.Net.Mail.MailMessage objEmail = new System.Net.Mail.MailMessage();
        objEmail.From = new MailAddress("caio.jesus@ex.com", "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("caio.jesus@ex.com", "XXX");
        objSmtp.Send(objEmail);
CaioVJesus89
  • 333
  • 1
  • 11
  • 24

2 Answers2

6

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!

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
1

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

Harrison Paine
  • 611
  • 5
  • 14