MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("sendemail@gmail.com");
mailMessage.To.Add("receiveemail@mydomain.com");
mailMessage.Subject = "New Enquiry" ;
mailMessage.Body = "<b>Sender Name : </b>" + txt_name.Text + "<br/>"
+ "<b>Contact Number : </b>" + txt_number.Text + "<br/>"
+ "<b>Sender Email : </b>" + txt_email.Text + "<br/>"
+ "<b>Details : </b>" + txt_message.Text;
mailMessage.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials =
new System.Net.NetworkCredential("sendemail@gmail.com", "Password");
smtpClient.Send(mailMessage);
Response.Write("<Script>alert('Thanks for contact us,our team will be contact you as soon as possible')</Script>");
txt_name.Text = "";
txt_email.Text = "";
txt_number.Text = "";
txt_message.Text = "";
This is my ASP.NET C# code for sending emails through the website's contact us page. But Google has discontinued the less secure app access option as of May 30, 2022 due to security reasons. So now I'm not able to send emails using the above code.
Less Secure app access snapshot:
How can I deal with this so I can send email again?
