Beshoy Wageh

Beshoy Wageh

  • NA
  • 33
  • 4.6k

The SMTP server requires a secure connection or the client w

Jan 16 2019 6:56 AM
public void SendVerificationLinkEmail(string emailID, string activationCode)
{
var verifyUrl = "/User/VerifyAccount/" + activationCode;
var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);
var fromEmail = new MailAddress("[email protected]", "beshooooo");
var toEmail = new MailAddress(emailID);
var fromEmailPassword = "********"; // Replace with actual password
string subject = "Your account is successfully created!";
string body = "<br/><br/>We are excited to tell you that your Dotnet Awesome account is" +
" successfully created. Please click on the below link to verify your account" +
" <br/><br/><a href='" + link + "'>" + link + "</a> ";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword)
};
using (var message = new MailMessage(fromEmail, toEmail)
{
Subject = subject,
Body = body,
IsBodyHtml = true
})
smtp.Send(message);
}

Answers (2)