Solved

c# Office365 SMTP Exception received 5.7.1 Client was not authenticated

Posted on 2014-07-21
4
465 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Enabling the Skype for Business Meeting Scheduler in Hybrid OWA
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This Experts Exchange lesson shows how to use VBA to loop through rows in Excel.  In order to sort, filter, and use database features, there needs to be a value in each column for every row. When data arrives with values missing, code to copy values…

738 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