I have multiple email recipients stored in SQL Server. When I click send in the webpage it should send email to all recipients. I have separated emails using ;
.
Following is the single recipient code, which works:
MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress(fromEmail);
Msg.From = fromMail;
Msg.To.Add(new MailAddress(toEmail));
if (ccEmail != "" && bccEmail != "")
{
Msg.CC.Add(new MailAddress(ccEmail));
Msg.Bcc.Add(new MailAddress(bccEmail));
}
SmtpClient a = new SmtpClient("smtp server name");
a.Send(Msg);
sreader.Dispose();
MailMessage
andSmtpClient
instances need to be inusing
blocks. – OrthodonticsSmtpClient
in particular has been known to not send until disposed. I had a Web app that wasn't disposing. We could measure 2 minutes before the message was actually sent. – Orthodonticsusing
blocks" does not equal "needs to be disposed". Second, in production code like web applications you will usually want to useSendAsync
anyways, which works as intended without the need to dispose theSnmpClient
instance. – Dipteran