Search code examples
asp.net-mvclayoutsendmailareamvcmailer

MvcMailer Areas and _Layout Issue


I am using MvcMailer for sending email in my project.

everything OK but when I send email in admin area, email is sent with admin area layout, and It doesn't use "~/View/UserMailer/_Layout.cshtml".

In Github of this project, some one discuss this issue but no one didn't has answered.

Does anyone have any idea?


Solution

  • Rename the _Layout.cshtml in your mailer folder to something else such as _LayoutMailer.cshtml

    Rename the MasterName in your mailer constructor in UserMailer.cs to the same as follows:

    public class UserMailer : MailerBase
    {
        public UserMailer()
        {
            MasterName = "_LayoutMailer";
        }
        ...
    }