Hassan Mokdad
Hassan Mokdad

Reputation: 5902

The SMTP server requires a secure connection or the client was not authenticated error while sending email from asp.net

I am trying to send an email from my asp.net application, the function worked fine on my machine, but when I deployed it on the webserver, I got the error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required,

Any one can help? Thanks

Upvotes: 5

Views: 37655

Answers (4)

Sudheesh
Sudheesh

Reputation: 61

Go to your mail server and check your firewall settings. Then goto gmail, add your server address in gmail secured client list from account settings.

Upvotes: 3

Sajith A.K.
Sajith A.K.

Reputation: 734

Please try this

private void MailSendThruGmail()
    {
        MailAddress fromAddress = new MailAddress("[email protected]", "From Name");
        MailAddress toAddress = new MailAddress("[email protected]", "To Name");
        const string subject = "test";
        const string body = @"Using this feature, you can send an e-mail message from an application very easily.";

        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body);
        msg.IsBodyHtml = true;

        var client = new SmtpClient("smtp.gmail.com", 587)
        {
            Credentials = new NetworkCredential("username", "password"),
            EnableSsl = true
        };

        try
        {
            client.Send(msg);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
    }

Upvotes: 6

Hassan Mokdad
Hassan Mokdad

Reputation: 5902

Finally I managed to solve it, The SSL should be enable on the webserver as well, here is a link to enable ssl on the IIS7

http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx

Upvotes: 8

Kinexus
Kinexus

Reputation: 12904

Are you part of a domain and the SMTP server is also on this domain. If this is the case, it could be that you are being authenticated by Windows authentication automatically and the user that IIS is running under is probably local to the machine it is on. You could either run the app pool under a domain user and use impersonation (not tested, but should work) or add some credentials to the SMTP server programatically when sending the email.

Upvotes: 0

Related Questions