Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error Geting The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. My code as
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       MailMessage mail = new MailMessage();
       SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
       mail.From = new MailAddress("mirajmishra1992@gmail.com");
       mail.To.Add(YourEmail.Text.ToString());
       mail.Subject = YourName.Text.ToString();
       mail.Body = Comments.Text.ToString();
       SmtpServer.Port = 587;
       SmtpServer.Credentials = new System.Net.NetworkCredential("RajnishMishra", "computer");
       SmtpServer.EnableSsl = true;
       SmtpServer.Send(mail);
      // MessageBox.Show("mail Send");
  }
Posted
Updated 21-Nov-14 19:07pm
v3

http://www.codeproject.com/Answers/273383/sendind-mail-using-smtp-in-asp-net#answer2
 
Share this answer
 
Solution:

a) go to gmail security center via this link blow or google search for “gmail secrity” and login with your gmail account
https://accounts.google.com/ServiceLogin?elo=1

b) next to “security” / “Recent activity” , click to “view all events”

c) You will able to see “Unusual Activity” , it will show all unusual activity events, select related event and approval it via click ” Yes, That was me!”


// Click allow access to your Google account

d) https://accounts.google.com/DisplayUnlockCaptcha[^]
 
Share this answer
 
v3
using (MailMessage mm = new MailMessage("from email", "To email")
               {

                   StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/HtmlPage.html"));
                   string readFile = reader.ReadToEnd();
                   string myString = "";
                   myString = readFile;
                   string fname=dttemp.Rows[0][1].ToString();
                   myString = myString.Replace("$$fname$$", fname);
                   mm.Subject = "Your Subject";
                   mm.Body = myString.ToString();
                   mm.IsBodyHtml = true;
                   SmtpClient smtp = new SmtpClient();
                   smtp.Host = "smtp.gmail.com";
                   smtp.EnableSsl = true;
                   NetworkCredential NetworkCred = new NetworkCredential("from Email", "From Password");
                   smtp.UseDefaultCredentials = false;
                   smtp.Credentials = NetworkCred;
                   smtp.Port = 587;
                   smtp.Send(mm);

               }
 
Share this answer
 

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