0
// send Email
string toEmailAddress = dt.Rows[0][4].ToString();
string Username = dt.Rows[0][1].ToString();
string EmailBody = "Hi "+Username+ "<br/> click the link below to reset your password<br/> http://localhost:51583/RecoveryPass.aspx?Uid="+myGUID;
MailMessage PassRecMail = new MailMessage("youremail@gmail.com",toEmailAddress);
PassRecMail.Body = EmailBody;
PassRecMail.IsBodyHtml = true;
PassRecMail.Subject = "Reset Password";

SmtpClient SMTP = new SmtpClient();

SMTP.Port = 587;
SMTP.Host = "smtp.gmail.com";
SMTP.EnableSsl = true;
SMTP.UseDefaultCredentials = false;
SMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
SMTP.Credentials = new NetworkCredential()
{
    UserName= "youremail@gmail.com",
    Password= "yourGmailPassword"
};
SMTP.UseDefaultCredentials = false;

SMTP.Send(PassRecMail);

I am getting this error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. at line SMTP.Send(PassRecMail);

I have turned on google less security then also i am getting this error. How can I solve it?

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
  • 1
    Have a read of https://stackoverflow.com/questions/17227532/gmail-530-5-5-1-authentication-required-learn-more-at and https://productforums.google.com/forum/#!topic/gmail/vtTz1ngyH8o . – mjwills Jun 11 '17 at 07:01
  • Possible duplicate of [Sending email in .NET through Gmail](https://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – VDWWD Jun 11 '17 at 11:47

1 Answers1

1

1st you will define .......

using System.Net.Mail;

using System.Data.SqlClient;

using System.Data;

using System.Net;

using System.Drawing;

then We can create a new gmail id(I think it best ) then .......

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

    smtpClient.Credentials = new System.Net.NetworkCredential()
    {
        UserName = "shopify580@gmail.com",
        Password = "********"
    };

    smtpClient.EnableSsl = true;
    smtpClient.Send(mailMessage);
Raju
  • 622
  • 6
  • 10