public static void sendMail(List<User> users, string subject, string body)
{
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
for (int i = 0; i < users.Count(); i++)
{
message.To.Add(users[i].Email);
}
message.Subject = subject;
message.Body = body;
message.IsBodyHtml = true;
SmtpClient emailClient = new SmtpClient();
emailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
Object userState = message;
try
{
//Send the email asynchronously
emailClient.SendAsync(message, userState);
}
catch (SmtpException smtpEx)
{
MailMessage errorMailAlert = new MailMessage();
errorMailAlert.From = new MailAddress(from);
errorMailAlert.To.Add(new MailAddress("randomise@scri.edu.sg"));
errorMailAlert.Subject = "Send Mail Failure";
errorMailAlert.Body = "system has failed to a mail. Details of the error is stated below and can be viewed" +
" in the MailLog under the rand log folder.<br/><br/>Exception details:<br/>" + smtpEx.ToString();
errorMailAlert.IsBodyHtml = true;
//try sending message to the admin
try
{
//Send the email asynchronously
emailClient.SendAsync(errorMailAlert, userState);
}
catch (SmtpException smtpEx2)
{
//Error handling here
ExceptionUtility.LogMailException(smtpEx2);
}
//Error handling here
ExceptionUtility.LogMailException(smtpEx);
}
catch (Exception ex)
{
//Error handling here
ExceptionUtility.LogMailException(ex);
}
}
catch
{
throw;
}
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE