I want to send email with my html template and i have my cshtml template with model but i can't convert it to string for email body:
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.Subject = subject;
mail.Body = ?
You can use MimeMessage instead of MailMessage
How to work with it is as follows.
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress(MailConfig.FromName, MailConfig.FromAddress));
emailMessage.To.Add(new MailboxAddress(toName, toAddress));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(TextFormat.Html) {Text = body};
As you can see, TextPart class is used to set the Body value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.