rohit bucha
rohit bucha

Reputation: 1

C# Getting a Forgot Password link via Email

// 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("[email protected]",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= "[email protected]",
    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?

Upvotes: 0

Views: 2655

Answers (1)

Raju
Raju

Reputation: 632

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 = "[email protected]",
        Password = "********"
    };

    smtpClient.EnableSsl = true;
    smtpClient.Send(mailMessage);

Upvotes: 1

Related Questions