Solved

c# Office365 SMTP Exception received 5.7.1 Client was not authenticated

Posted on 2014-07-21
4
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
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…

726 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