Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this is my code for email notification-
C#
NetworkCredential smtpCreds = new NetworkCredential("hostemail", "hostpassword");
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        //  smtp.Credentials = new NetworkCredential(TextBox1.Text, TextBox1.Text);
        MailMessage mail = new MailMessage("xxxxxxxx@gmail.com", Emailtxt.Text, "Registration Details", bodytxt.Text);
        smtp.Send(mail);

Error in my code is-
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

[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) +1450559
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +41
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +97
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1757
   UserReg.Submitbtn_Click(Object sender, EventArgs e) in c:\HILProject\project4\UserReg.aspx.cs:42
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563


[Edit]Email removed to avert spambots[/Edit]
Posted
Updated 8-May-14 6:51am
v3
Comments
CHill60 8-May-14 12:52pm    
I would suggest that the credentials you are supplying are incorrect

you need to set smtp.Credentials and remove the line smtp.UseDefaultCredentials = false;
C#
NetworkCredential smtpCreds = new NetworkCredential("username", "pw");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.Credentials = smtpCreds;
MailMessage mail = new MailMessage("xxxxxxxx@gmail.com", Emailtxt.Text, "Registration Details", bodytxt.Text);
smtp.Send(mail);
 
Share this answer
 
Comments
Ashwini Thakare 26-May-14 1:06am    
thanks for your suggestion.
It worked.
thanks a lot
DamithSL 26-May-14 1:11am    
You are welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900