crossvertise / ActionMailerNext

Fork of ActionMailer.Net, A easy to use library to generate emails with razor views
MIT License
42 stars 24 forks source link

NoViewsFoundException: cannot find view... or layout file #7

Open gmmHls opened 9 years ago

gmmHls commented 9 years ago

Here is a part of the exception message : [NoViewsFoundException: You must provide a view for this email. Views should be named EmailVerify.html.cshtml.txt.cshtml or EmailVerify.html.cshtml.html.cshtml (or aspx for WebFormsViewEngine) depending on the format you wish to render.] ActionMailerNext.Mvc5_2.EmailResult.AddMessageViews(ControllerContext context) +351 ActionMailerNext.Mvc5_2.EmailResult.ExecuteResult(ControllerContext context) +48 ActionMailerNext.Mvc5_2.MailerBase.Email(String viewName, Object model, String masterName, Boolean trimBody) +724 ...

here is my controller and action method: /////////////////////////////////// public class EmailServiceController : MailerBase { public EmailResult EmailVerify(ApplicationUser user) { //Choosing the Email method (SMTP, Mandrill, etc..) SetMailMethod(MailMethod.SMTP); // Setting up needed properties MailAttributes.From = new MailAddress("info@domain.com", "domain.com"); MailAttributes.To.Add(new MailAddress("user@email.club")); //(user.Email)); MailAttributes.Subject = "Registration Email Verification"; MailAttributes.Priority = MailPriority.High; //Calling the view which form the email body return Email("EmailVerify.html.cshtml", user); } } ///////////////////////////////////

The actual name of my view is "EmailVerify.cshtml" and it is in the "Views/EmailService" folder. I tried to change the view name to "EmailVerify", "EmailVerify.cshtml", "EmailVerify.html.cshtml" without success.

What do I miss here?

Thanks

gmmHls commented 9 years ago

OK, I see what was wrong. The name of the view itself needs the additional .text.html or .html.cshtml. However, now it tells me that it cannot find the layout view in the EmailVerify.html.cshtml view. Is it not possible to use a layout / master for my view??

JamesReate commented 9 years ago

If you run in debug mode, when you look at the exception, there should be a property with the full path. You can use that to validate it is the correct path. Also, are you running standalone or mvc etc?

gmmHls commented 9 years ago

Thanks for your answer. It was the path to the layout , I missed the "~". And I use it MVC 5.2. Here is what I have now, may be it may help others: My Controller: public class EmailServiceController : MailerBase

my action method: // GET: EmailVerify public EmailResult EmailVerify(ApplicationUser user) { //Choosing the Email method (SMTP, Mandrill, etc..) SetMailMethod(MailMethod.SMTP); // Setting up needed properties MailAttributes.From = new MailAddress("info@domain.com", "domain.com"); MailAttributes.To.Add(new MailAddress("user@email.club")); //(user.Email)); MailAttributes.Subject = "Registration Email Verification"; MailAttributes.Priority = MailPriority.High; // Adding some attachment //MailAttributes.Attachments["attachment.zip"] = File.ReadAllBytes("C:/attachment.zip"); //Calling the view that forsm the email body return Email("EmailVerify", user); }

My Views: (folder)View (folder)EmailService _EmailLayout.cshtml _EmailVerify.html.cshtml

the source for the _EmailLayout: <!DOCTYPE html> @{ Layout = null; }

@ViewBag.Title
 LOGO HERE
@RenderBody()

This email was sent from Domain.com where this email address is registered!

The source for the EmailVerify: @using ActionMailerNext @model Identity2Api2Mvc5.Models.ApplicationUser @{ Layout = "~/Views/EmailService/_EmailLayout.cshtml"; }

Welcome @Model.UserName

You are almost there.

Please confirm your registration with domain.com by going to:

http://domain.com/confirm?id=@Model.Id

After your confirmend the receipt of this email, you will be able to log in with your email as username and the password you entered during the rigistration process.

Welcome again

The Domain.com Team

Thanks again for your help. gmm