when i try to send a mail from my asp.net web forms could not send. while trying to debugging, time out issue occur. actually it was working fine in last year. but currently it is not working.i dont know what happen this code. this is my aspx.cs code
public static void SendByMail(string responseBody, string Subject)
{
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]", "abcd.com");
message.To.Add(new MailAddress("[email protected]"));
message.Subject = Subject;
message.Body = responseBody;
message.IsBodyHtml = true;
message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = false;
NetworkCredential myCreds = new NetworkCredential("[email protected]", "password", "");
client.Credentials = myCreds;
client.EnableSsl = true;
client.Send(message);
}
catch //(Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
CodePudding user response:
Since March 2022, Google has strengthened the security of access to your account via a third-party application.
For this, you should not use your own password to log into your account, but rather generate a password via your account.
To do that, make sure that your two-step verification is on. Now, go to the "Manage your Google Account", then click the "Security" tab.
Now, click the App passwords option. Finally, you can select a Custom name for your app.
Once the password is generated, you will have to put it in place of your real password.