McvMailer does not see views

I want to use MvcMailer in my application. I created a new class library project called MyMailer. Now I want to use it in my MVC application.

// mailer public class MyMailer : MailerBase, IEdoctorMailer { public MyMailer() { MasterName = "_Layout"; } public virtual MvcMailMessage Invitation() { //ViewBag.Data = someObject; var msg = Populate(x => { x.Subject = Labels.Invitation; x.ViewName = "Invitation"; x.From = new MailAddress(" xxx@gmail.com "); x.To.Add(" yyy@gmail.com "); }); return msg; } } //mvc controller IMyMailer mailer = new MyMailer(); var inv = mailer.Invitation(); inv.Send(new DefaultSmtpClient()); // see below public class DefaultSmtpClient : SmtpClient, ISmtpClient { public DefaultSmtpClient() : base("smtp.gmail.com", 587) { EnableSsl = true; UseDefaultCredentials = false; Credentials = new NetworkCredential("login", "pass"); } public void SendAsync(MailMessage mailMessage) { throw new NotImplementedException(); } } 

In the MyMailer project in Views/MyMailer/Invitation.cshtml there is a file with some text in it.

When I send an email, it really comes. But this invitation is not included (no body at all). I guess this is because the submit method is executed from the mvc project, but this is just my guess.

I even set a breakpoint in Views/MyMailer/_Layut.cshtml --> RenderBody() , but it never entered it.

What should I do to enable the presentation?

0
source share
1 answer

Since you see MvcMailer in the class library, you need to tell the MVC project where and how to find them by overriding ViewEngine or VirtualPathProvider.

+2
source

All Articles