asp.net-mvcemailsendasync

Is there any way to set SendEmailAsync to isHtml= true?


I am working on Forgot Password Functionality in Asp.Net MVC.

I am able to successfully send forgot password link to email thorugh SendEmailAsync Method, but email is isHtml = false.

How can I make it to true?

public Task SendAsync(IdentityMessage message)
{
   SmtpClient client = new SmtpClient();
   return client.SendMailAsync("email",
                                    message.Destination,
                                    message.Subject,
                                    message.Body);
}

Solution

  • You need to use another overload which takes a MailMessage object. For example:

    SmtpClient client = new SmtpClient();
    var message = new MailMessage();
    message.IsBodyHtml = true;
    message.Body = "email";
    //Set other properties such as subject etc.
    return client.SendMailAsync(message);