smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
584 stars 178 forks source link

Issue using MVCMailer with webforms #46

Open GeorgeJohn opened 12 years ago

GeorgeJohn commented 12 years ago

Have an MVC project that uses a few webforms in it - we are in the process of converting them over. One of the pages happens to render a report. I'm trying to add the ability to email the report if the user wants to. When trying to use MvcMailer to achieve this it seems that it cannot find the view when I try to make the "PopulateBody" call

Here is my code from the UserMailer class

public class UserMailer : MailerBase, IUserMailer { ///

/// Email Reports using this method
/// </summary>

/// <param name="toAddress">The address to send to.</param>
/// <param name="viewName">The name of the view.</param>
/// <returns>The mail message</returns>
public MailMessage SendReport(string toAddress, string viewName)
{
    var message = new MailMessage { Subject = "Report Mail" };
    message.To.Add(toAddress);
    ViewBag.Name = "Testing-123";

    this.PopulateBody(mailMessage: message, viewName: "SendReport");

    return message;
}

}

Every time I hit the populateBody call it responds with "Value cannot be null. Parameter name: routeData"

Any suggestions to overcome this would be quite helpful.

smsohan commented 12 years ago

Are you using is offline or on a background job? The MailerBase subclass needs to be in a web project and need to run under a web server just like

your controllers.

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Tue, May 8, 2012 at 2:04 PM, GeorgeJohn < reply@reply.github.com

wrote:

Have an MVC project that uses a few webforms in it - we are in the process of converting them over. One of the pages happens to render a report. I'm trying to add the ability to email the report if the user wants to. When trying to use MvcMailer to achieve this it seems that it cannot find the view when I try to make the "PopulateBody" call

Here is my code from the UserMailer class

public class UserMailer : MailerBase, IUserMailer { ///

/// Email Reports using this method ///

/// The address to send to. /// The name of the view. /// The mail message public MailMessage SendReport(string toAddress, string viewName) { var message = new MailMessage { Subject = "Report Mail" }; message.To.Add(toAddress);

   ViewBag.Name = "Testing-123";

   this.PopulateBody(mailMessage: message, viewName: "SendReport");

   return message;

} }

Every time I hit the populateBody call it responds with "Value cannot be null. Parameter name: routeData"

Any suggestions to overcome this would be quite helpful.


Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/46

GeorgeJohn commented 12 years ago

No, not using it offline or on a background job. I have an aspx page that is creating my report for me that I want to attach to the mail. In there I call the SendReport method in the UserMailer. I can step through all the way to the PopulateBody method and there I get this error.

Mvc.Mailer is referenced in the web project. Are you suggesting that I need to add the actual MailerBase into my web project? Sorry just trying to clarify what you are suggesting.

smsohan commented 12 years ago

I will try to take a look at it tonight.

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Tue, May 8, 2012 at 3:56 PM, GeorgeJohn < reply@reply.github.com

wrote:

No, not using it offline or on a background job. I have an aspx page that is creating my report for me that I want to attach to the mail. In there I call the SendReport method in the UserMailer. I can step through all the way to the PopulateBody method and there I get this error.

Mvc.Mailer is referenced in the web project. Are you suggesting that I need to add the actual MailerBase into my web project? Sorry just trying to clarify what you are suggesting.


Reply to this email directly or view it on GitHub: https://github.com/smsohan/MvcMailer/issues/46#issuecomment-5587644

GeorgeJohn commented 12 years ago

No worries. Thanks for the quick response. If it helps I also put together a test project where I just have a button on an aspx page and that in turn is just trying to call the welcome method in the UserMailer class. I get the same issue there as well. If you need me to zip up the project and send it to you I'd be more than happy to do so.

GeorgeJohn commented 12 years ago

Were you ever able to look at this?