12

似乎当我使用 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 ...
4

2 回答 2

16

一种选择是使用 Razor 部分。

在布局顶部添加:

@RenderSection("Headers")

然后在视图中添加:

@section Headers {
    To:  @ViewBag.To
    From: @ViewBag.From
    Subject: Reset Password
    Views: Html
}
于 2014-04-23T08:32:13.053 回答
0

移动第一行

内容类型:文本/html;字符集=utf-8

从 Views/Emails/ResetPassword.html.cshtml 到 Views/Emails/_EmailLayout.cshtml

Content-Type: text/html; charset=utf-8
<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>ViewEmails</title>
    </head>
    <body>
        <div>
            @RenderBody()
        </div>
    </body>
</html>
于 2014-04-21T10:01:45.083 回答