Intermittent failure with Office SMTP server

the typical cause is a message overload. Usually the next try will succeed: in case of problems on your server it will come with a side-message like “Out of memory”. An error of your mail server, often due to an issue of the local anti-spam filter. Contact your SMTP service provider to fix the situation.

Intermittent failure with Office SMTP server

I'm sending about 2-3000 email a day using Office 365 smtp server. 99% of the emails are sent correctly but about 1% of the time I get the following error :

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM.

Here is my code :

private void SendEmail(string strTo, string strFrom, string strMessage, string strSubject, bool htmlFormat = true)
{
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    System.Net.Mail.MailAddress mto = new System.Net.Mail.MailAddress(strTo);
    System.Net.Mail.MailAddress mfrom = new System.Net.Mail.MailAddress(strFrom);
    mail.Subject = strSubject;
    mail.From = mfrom;
    mail.To.Add(mto);
    mail.Body = strMessage;
    mail.IsBodyHtml = htmlFormat;
    System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.office365.com", 587);
    mailClient.Timeout = 1000000;
    mailClient.EnableSsl = true;
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = new System.Net.NetworkCredential("my@emailaddress.com", "mypassword");
    mailClient.Send(mail);

Click Here to Visit

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0