Solved

c# Office365 SMTP Exception received 5.7.1 Client was not authenticated

Posted on 2014-07-21
4
417 Views
Last Modified: 2016-04-01
I am trying to send an email from within a c# app via Office365.

I am receiving the following error:

[test out message sending] System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.

My code is simple at the moment
        public static void SendMail()
        {
            SmtpClient client = new SmtpClient("smtp.office365.com", 587);
            client.EnableSsl = true;

            client.Credentials = new System.Net.NetworkCredential("me@bubbles.com", "Pa55w0rd");
            client.Timeout = 5000;
            client.UseDefaultCredentials = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress("me@bubbles.com");
            mail.To.Add("friend@bubbles.com");
            mail.Subject = "test out message sending";
            mail.Body = "this is my message body";
            mail.IsBodyHtml = true;

            client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);

            client.SendAsync(mail,mail);
            Console.WriteLine("Sending Message...");
        }

        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)
        {
            // Get the unique identifier for this asynchronous operation.
            MailMessage msg = (MailMessage)e.UserState;

            if (e.Cancelled)
            {
                Console.WriteLine("[{0}] Send canceled.", msg.Subject);
            }
            if (e.Error != null)
            {
                Console.WriteLine("[{0}] {1}", msg.Subject, e.Error.ToString());
            }
            else
            {
                Console.WriteLine("Message sent.");
            }

        }

Open in new window


I've looked through lots of posts for this, but solutions recommended do not seem to change my fault.
0
Comment
Question by:west-com
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Mitchell Milligan earned 250 total points
ID: 40209403
In office 365, port 587 requires authentication, and to have the sending ip address added as a connector in the panel to trust the incoming message.  Alternatively you can use port 25 for SMTP to office 365 and it should go through without a trust issue.  You can see more about that here: How to Allow a Multi-function Device or Application to Send E-mail through Office 365 Using SMTP
0
 
LVL 9

Assisted Solution

by:xav056
xav056 earned 250 total points
ID: 40209429
Sign in through OWA and verify your mailbox address from the help icon
see if replacing smtp.office365.com with your actual server name resolves it.
0
 

Author Comment

by:west-com
ID: 40213837
Many thanks for these two. I've just been dragged off this project for a couple of days. Will try these two options shortly. I wanted to avoid port 25 as many of our clients block port 25 on the router to all but the mail server to prevent viruses emailing from PCs and causing the external IP being Blacklisted.
0
 

Author Comment

by:west-com
ID: 41531603
Both solutions worked. Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Pop culture is prime bait for hackers seeking to infect user’s computers and mobile devices with malicious malware. Hackers know exactly what the latest trends are online and know how to use them to their advantage.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question