It seems when I use Postal to send an email using Layout, the headers was not parsed and included on the mail message.
Views/Emails/_ViewStart.cshtml
@{ Layout = "~/Views/Emails/_EmailLayout.cshtml"; }
Views/Emails/_EmailLayout.cshtml
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ViewEmails</title>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
Views/Emails/ResetPassword.cshtml
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
Views/Emails/ResetPassword.html.cshtml
Content-Type: text/html; charset=utf-8
Here is your link, etc ...
When i received the mail all the headers To, From, Subject and Views are included in the body.
Anyone know how to do it correctly ?
UPDATED (Thanks to Andrew), this works :
Views/Emails/_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>
Views/Emails/ResetPassword.cshtml
@section Headers {
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
}
Views/Emails/ResetPassword.html.cshtml
@section Headers {
Content-Type: text/html; charset=utf-8
}
Here is your link, etc ...
Postal can work with any ASP.NET MVC view engine. Postal uses SmtpClient, which can be configured in Web.config. Learn more… Not everyone likes using dynamic objects. Postal lets you strongly type your email data if you need to. Learn more… Verify that your code would send emails, without actually sending them. Learn more…
Install Postal into your ASP.NET web application using Nuget. Use Postal in your controller action method. Create an Email, passing it the name of the view to use for the email.
Learn more… Not everyone likes using dynamic objects. Postal lets you strongly type your email data if you need to. Learn more… Verify that your code would send emails, without actually sending them.
Whatever look you want to give to your header do it here. Now again right-click on the Shared Folder and select Add-> View. Image 6. Image 7. Now add a View by right-clicking on the Action Method Name and select your Layout or Master Page like the following.
One option is to use a Razor section.
At the top of the layout add:
@RenderSection("Headers")
Then in the view add:
@section Headers {
To: @ViewBag.To
From: @ViewBag.From
Subject: Reset Password
Views: Html
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With