When I sent mail using System.Net.Mail, it seems that messages are not sent immediately. They take a minute or two before reaching my inbox. As soon as I exit the application, all messages are received within a few seconds. Is there some kind of message buffer setting that could cause SmtpClient to send messages immediately?
public static void SendMessage(string smtpServer, string mailFrom, string mailFromDisplayName, string[] mailTo, string[] mailCc, string subject, string body) { try { string to = mailTo != null ? string.Join(",", mailTo) : null; string cc = mailCc != null ? string.Join(",", mailCc) : null; MailMessage mail = new MailMessage(); SmtpClient client = new SmtpClient(smtpServer); mail.From = new MailAddress(mailFrom, mailFromDisplayName); mail.To.Add(to); if (cc != null) { mail.CC.Add(cc); } mail.Subject = subject; mail.Body = body.Replace(Environment.NewLine, "<BR>"); mail.IsBodyHtml = true; client.Send(mail); } catch (Exception ex) { logger.Error("Failure sending email.", ex); }
Thanks,
Mark
source share