Quantcast
Channel: Sending email error - SMTP Server requires a secure connection 5.5.1
Viewing all articles
Browse latest Browse all 11

Re: Sending email error - SMTP Server requires a secure connection 5.5.1

$
0
0

This is my new updated code:

protected void Button1_Click(object sender, EventArgs e)
    {
        // Create a message and set up the recipients.
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        message.To.Add("mymail@domain.com");
        message.Subject = "Form - ";
        message.IsBodyHtml = true;
        message.Priority = MailPriority.High;
        message.Body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
        message.Body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
        message.Body += "</HEAD><BODY>";

        message.Body += "<table border='1'><tr><td>Textbox1.Text</td><td>Textbox2.Text</td></tr><tr><td>Textbox3.Text</td><td>Textbox4.Text</td></tr></table>";
        message.Body += "</BODY></HTML>";

               // Send the message.
        smtpClient.Port = 587;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new System.Net.NetworkCredential("mygmailusername@gmail.com", "password");


        smtpClient.EnableSsl = true;

        smtpClient.Send(message);
        EmailSentForm.Visible = Visible;
}



This is my webconfig:

<mailSettings><smtp from="mygmailadd@gmail.com"><network host="smtp.gmail.com" password="gmailpassword" port="587"
userName="mygmailadd@gmail.com" /></smtp></mailSettings>



I am getting this error now:

Server Error in '/' Application.


The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Source Error: 

Line 62:         smtpClient.EnableSsl = true;
Line 63:         Line 64: smtpClient.Send(message); Line 65:         EmailSentForm.Visible = Visible;
Line 66:         
<div>Stack Trace: 

[SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +1432119
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) +46
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) +88
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1852
</div>

Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>