我想在mvc中发送电子邮件正文中的视图。 请指导如何呈现视图,以便它可以作为html电子邮件正文发送。
谢谢,
答案 0 :(得分:3)
考虑使用ActionMailer之类的内容。您可以使用NuGet下载它。
答案 1 :(得分:0)
string path = ConfigurationManager.AppSettings["ProjectPath"] ; string gmailpath = path + "/" + "Driver/VerificedAccount?code=" + root.Result.EmailVerificationCode;
var body= "<html><body><p></p><p><a href = "+gmailpath+" > Please click Verifed Account </a></p></body></html> ";
var st = EmailclassHtml(sendemail.Email, "Verification-Driver", body);
public string EmailclassHtml(string email, string subjectname, string messgae) {
string ownemail = ConfigurationManager.AppSettings["SenderEmail"];
string ownname = ConfigurationManager.AppSettings["SenderName"];
string returnmessage = "success";
var senderEmail = new MailAddress(ownemail, ownname);
var receiverEmail = new MailAddress(email, "Receiver");
var password = ConfigurationManager.AppSettings["SenderPassword"];
var sub = subjectname;
var body = messgae;
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = true,
Credentials = new NetworkCredential(senderEmail.Address, password)
};
using (var mess = new MailMessage(senderEmail, receiverEmail)
{
Subject = sub,
Body = body,
IsBodyHtml = true
})
try
{
smtp.Send(mess);
return returnmessage;
}
catch (Exception)
{
returnmessage = "fail";
}
return returnmessage;
}