Question

Hi I am using MVC Mailer to manage creating and sending emails in my application. It will create and send the email fine but any html I insert inside the body in the layout is not in the email.

Mailer

public class Mailer : MailerBase, IMailer
{
    public aMailer()
    {
        MasterName = "_EmailLayout";
    }

    public virtual MvcMailMessage RequestAccess(RequestAccessViewModel viewmodel)
    {
        ViewData.Model = viewmodel;

        return Populate(x =>
        {
            x.Subject = "RequestAccess for Data";
            x.ViewName = "RequestAccess";
            x.To.Add("AppTeam@groups.hp.com");
            x.From = new MailAddress(viewmodel.Email);
        });
    }
}

I am setting it to use _EmailLayout here, I cahnged the name after seeing that there was an issue with naming it _Layout because it would conflict with any other files named _Layout.

_EmailLayout

<html>
<head>
</head>
<body>
    <h1>Mailer</h1>
    @RenderBody()

    Thanks
</body>

The contents of the H1 tag or "Thanks" are not in the email

Access.cshtml

<h3>"This is a Application email." </h3>
<p>@Model.Message</p>
<br/>
<p>Regards</p>
<p>@Model.Name</p>
<p>Business Area: @Model.BusinessArea</p>

Email Source

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><title></title>
</head>
<body>

    <p> Hi jeff test,</p>
    <br>
    <p>Thank you for your enquiry about the Application.</p>
    <br>

</body>

Has anyone come across this issue before? When I debug my application I can see that it is going into the _EmailLayout but I don't know why the HTML in that files is not rendered.

Was it helpful?

Solution

After posting the following issue on the github page for MVC Mailer Changing the layout code to this fixed the problem

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

  Mailer

  @RenderBody()

  Thanks

</body>
</html>

I'm not sure why this fixed the problem but it did.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top