gpt4 book ai didi

asp.net-mvc - 使用 Postal MVC 与布局解析标题作为邮件正文

转载 作者:行者123 更新时间:2023-12-04 00:52:24 25 4
gpt4 key购买 nike

当我使用 Postal 使用 Layout 发送电子邮件时,似乎没有解析标题并将其包含在邮件消息中。

View /电子邮件/_ViewStart.cshtml

@{ Layout = "~/Views/Emails/_EmailLayout.cshtml"; }

View /电子邮件/_EmailLayout.cshtml

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ViewEmails</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>

View /电子邮件/ResetPassword.cshtml
To:  @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html

View /电子邮件/ResetPassword.html.cshtml
Content-Type: text/html; charset=utf-8

Here is your link, etc ...

当我收到邮件时,所有标题都包含在正文中。

任何人都知道如何正确地做到这一点?

更新(感谢安德鲁),这有效:

View /电子邮件/_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>

View /电子邮件/ResetPassword.cshtml
@section Headers {
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
}

View /电子邮件/ResetPassword.html.cshtml
@section Headers {
Content-Type: text/html; charset=utf-8
}

Here is your link, etc ...

最佳答案

一种选择是使用 Razor 部分。

在布局的顶部添加:

@RenderSection("Headers")

然后在 View 中添加:
@section Headers {
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
}

关于asp.net-mvc - 使用 Postal MVC 与布局解析标题作为邮件正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23154829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com