Email template not rendering model data
See original GitHub issueThis may be me missing something really obvious, but I am not able to replace the @Model.Strings components in my email template properly. I am using the latest version of .NET Core on a new project.
Here is my controller code starting the email send off.
Email.DefaultRenderer = new RazorRenderer();
Email.DefaultSender = new SendGridSender("KEY");
var email = Email
.From("do-not-reply@company.io", "Company")
.To(model.Email)
.Subject("You have been invited to join " + company.Name + "!")
.UsingTemplateFromFile($"{Directory.GetCurrentDirectory()}/Views/Emails/StandardEmail.cshtml", new {
CallbackUrl = callbackUrl,
ButtonText = buttonText,
Footer = footer,
Body = body,
Header = header
});
await email.SendAsync();
Then my email file has several @Model.Footer
and based on what is seen above. I am not using any other special code in the email file besides the HTML.
The email properly sends as expected, but I receive the email with the @Model.Footer
text being shown, instead of the data being passed in the model above.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top Results From Across the Web
HTML email template is not rendering correctly
And when it comes to rendering in a web browser it looks just fine, but I open such email in the Outlook app...
Read more >How to render email template objects in custom module?
Hello I made a custom module that load data from email.template but the problem is that data not rendering and just showing as...
Read more >Email content not rendering when Pass custom relatedTo ...
I have tried to test with merge field in email template with EnvironmentId and contact, it works. Seems either the template is not...
Read more >Visualforce Email template is not rendering and it shows ...
Hello everyone, I have created a visualforce Email template that uses a visualforce component to display some records in a form of a...
Read more >Php Template not rendering when sent in email
Currently the email gets sent but the template does not get rendered. ... Render view template public function render( $file, $data = false...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please ensure you adding this line of code
// Using Razor templating package Email.DefaultRenderer = new RazorRenderer();
At your start up. This should work
I’m having the same problem.
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>WelcomeEmail</title> </head> <body> <div>Listee
<dl class="dl-horizontal"> <dt> FirstName </dt> <dd> @Model.FirstName </dd> <dt> LastName </dt> <dd> @Model.LastName </dd> <dt> EmailAddress </dt> <dd> @Model.EmailAddress </dd> </dl> </div> </body> </html>