我创建了MVC5项目。现在使用Mail发送概念。它工作正常。发送电子邮件效果很好。现在我计划在我的电子邮件中添加一些设计。我在App_Start / Template / EmailTEmplate.html
中创建了以下模板<html>
<body style="color:grey; font-size:15px;">
<font face="Helvetica, Arial, sans-serif">
<div style="position:absolute; height:100px;
width:600px; background-color:0d1d36; padding:30px;">
<img src="logo" />
</div>
<br />
<br />
<div style="background-color: #ece8d4;
width:600px; height:200px; padding:30px; margin-top:30px;">
<p>Dear {0},<p>
<p>Thank you</p>
</div>
</body>
</html>
此处我的控制器代码邮件发送到收件箱
public class ContactUsController : Controller
{
// GET: Contact
public ActionResult ContactUs()
{
return View();
}
[HttpPost]
public ActionResult ContactUs(MailModel objModelMail, HttpPostedFileBase fileUploader)
{
if (ModelState.IsValid)
{
string from = "xxx@gmail.com";
using (MailMessage mail = new MailMessage(from, objModelMail.To))
{
mail.Subject = objModelMail.Subject;
mail.Body = objModelMail.Body;
if (fileUploader != null)
{
string fileName = Path.GetFileName(fileUploader.FileName);
mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
}
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential networkCredential = new NetworkCredential(from, "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCredential;
smtp.Port = 587;
smtp.Send(mail);
ViewBag.Message = "Sent";
return View("ContactUs", objModelMail);
}
}
else
{
return View();
}
}
}
我希望我的收件箱邮件看起来不错?如何添加模板?
答案 0 :(得分:0)
您可以在视图页面中分配布局:
@{
Layout = "~/Views/Shared/_MyLayout.cshtml";
}
这是你的问题?