5

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

Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90

4 Answers4

8

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

Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90
6

Please try this

private void MailSendThruGmail()
    {
        MailAddress fromAddress = new MailAddress("sender@gmail.com", "From Name");
        MailAddress toAddress = new MailAddress("recipient@gmail.com", "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());
        }
    }
Sajith A.K.
  • 716
  • 9
  • 21
3

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.

Sudheesh
  • 61
  • 7
  • Thanks I managed to fix it using the steps below in the accepted answer, maybe your steps might help in other scenarios, Thanks any way – Hassan Mokdad Nov 08 '12 at 08:36
0

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.

ChrisBint
  • 12,773
  • 6
  • 40
  • 62