Solved

c# Office365 SMTP Exception received 5.7.1 Client was not authenticated

Posted on 2014-07-21
4
384 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 3

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

Can’t get the mobile email signature right?

Not having any luck when trying to create an email signature for mobile devices? Does the formatting keep messing up? Make sure you have great email signatures on all devices by using Exclaimer Cloud - Signatures for Office 365.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Microsoft Office Picture Manager has a Picture Shortcuts pane that shows a list with the Recently Browsed folders. While creating my video Micro Tutorial here at Experts Exchange showing How to Install Microsoft Office Picture Manager in Office 2013…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now