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
582 stars 178 forks source link

Only send Html or Text mail, also if views exist #98

Closed kevinbrechbuehl closed 11 years ago

kevinbrechbuehl commented 11 years ago

Hi,

I've integrated the MvcMailer into our project and it works perfectly. Our project is based on the Sitecore CMS where the author can create multiple mail items with different content. For each template he enters a text for the html mail and one for the text mail. For all of these mails a have one single Mailer/Action. Now, my problem is, that I have the following cases:

But currently it sends the mail based on if the views exists or not (in my case, html and text views exist, because I decide at runtime which mail part to send). With the following code I could fullfill this requirement:

public override bool TextViewExists(string viewName, string masterName)
{
    if (!this.hasTextPart)
        return false;

    return base.TextViewExists(viewName, masterName);
}

public override bool HtmlViewExists(string viewName, string masterName)
{
    if (!this.hashtmlPart)
        return false;

    return base.HtmlViewExists(viewName, masterName);
}

The "hasTextPart" and "hasHtmlPart" i set in my Action before calling the "Populate" method.

This isn't very nice and does not handle multiple actions, concurrency etc. Is there a better way for doing this? Is there a way out of the box and I didn't found it?

Thanks and best regards, Kevin

smsohan commented 11 years ago

This looks good to me. There's currently no API to select view types other than based on the existence of the files.