似乎当我使用 Postal 使用 Layout 发送电子邮件时,标头没有被解析并包含在邮件消息中。
视图/电子邮件/_ViewStart.cshtml
@{ Layout = "~/Views/Emails/_EmailLayout.cshtml"; }
视图/电子邮件/_EmailLayout.cshtml
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ViewEmails</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
视图/电子邮件/ResetPassword.cshtml
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
视图/电子邮件/ResetPassword.html.cshtml
Content-Type: text/html; charset=utf-8
Here is your link, etc ...
当我收到邮件时,所有标题 To、From、Subject 和 Views 都包含在正文中。
任何人都知道如何正确地做到这一点?
更新(感谢安德鲁),这有效:
视图/电子邮件/_EmailLayout.cshtml
@RenderSection("Headers", false)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ViewEmails</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
视图/电子邮件/ResetPassword.cshtml
@section Headers {
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
}
视图/电子邮件/ResetPassword.html.cshtml
@section Headers {
Content-Type: text/html; charset=utf-8
}
Here is your link, etc ...