Marwan Tushyeh
Marwan Tushyeh

Reputation: 1525

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated on Azure

I have an smtp client on a windows azure application, the client works fine on the simulator but throws an exception on the cloud instance.

The exception message is :

The SMTP server requires a secure connection or the client was not authenticated The server's response was 5.5.1 authentication required

I made sure that the credentials are correct on the cloud by printing them in command line, i also disabled the firewall.

P.S: i'm using gmail smtp server.

Here is my code:

 private void SetupClient()
    {
        _emailSetting = new EmailSetting();
        _smtpClient = new SmtpClient(_emailSetting.SMTP_Server, _emailSetting.Port);
        _smtpClient.EnableSsl = true;
        _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
        _smtpClient.Credentials = new NetworkCredential(_emailSetting.EmailUser, _emailSetting.EmailPass);
    }


    public void Report(String msg)
    {
        MailMessage mailMessage;

        if (_smtpClient == null)
        {
            SetupClient();
        }

        String receivers = String.Join(",", Receivers);
        mailMessage = new MailMessage(_emailSetting.EmailUser, receivers, "Error", msg);
        _smtpClient.Send(mailMessage);

    }

Upvotes: 1

Views: 2529

Answers (2)

JGilmartin
JGilmartin

Reputation: 9298

One way to fix this is to RDP onto your Azure VM and log into your Gmail account from there. Google will ask you to confirm your account as it things it’s a "strange" location. Once verified your email will work fine.

Upvotes: 0

Piotr Stapp
Piotr Stapp

Reputation: 19830

I similar problem. The solution was quite "strange", gmail block my emails from azure, because your app is trying to log in from "strange" location. Try to check if you get notification/email in your gmail with information about block login.

Upvotes: 1

Related Questions