Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Using the Razor view engine to create email templates, quickly pluggable into your .NET app.
JavaScript C# PowerShell CSS Other
Branch: master
Pull request Compare This branch is 5 commits ahead, 12 commits behind NickJosevski:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.nuget
Build
ConsoleRunner
EmailModule.Specs
EmailModule
ExperienceTesting
Templates
ThirdParty/ILMerge
lib
.gitignore
Build.bat
PriorBugs.md
README.md
RunMeToBuildAndPackage.bat
Settings.StyleCop
mailzor-only.sln
mailzor.proj
mailzor.sln
mailzor.snk

README.md

mailzor

Mailzor is a basic utility library to help generate and send emails using the Razor view engine to populate email templates, designed to be quickly pluggable into your .NET app.

The original idea for this is from Kazi Manzur Rashid, with the...

This fork

Is about making it easier to get up and running, via a nuget package and support for IoC wireup.

  • A single entry point via IEmailSystem
  • Send message via SendMail on IEmailSystem
  • Some additional template loading checking, to ensure they're available and that it reports when it can't find them (in particular which template it couldn't find).

NuGet

Current Version: 1.0.0.11

Get it from nuget.org/packages/mailzor or via Package Manager Console

PM> Install-Package mailzor

Testing

In the repository open \ExperienceTesting\Mvc4TestApp\Mvc4TestApp.sln - it makes use of the nuget package. It's also an example of the MailzorModule Autofac wireup logic.

Have smpt4dev running or configure it to a real mail server and see it deliver a test message.

  • Functions with:
    • Razor 1.0 in ASP.NET MVC 3
    • Razor 2.0 in ASP.NET MVC 4

Building from source

Run build.bat which calls out to a psake script mailzor-build.ps1. The dependant Razor assembly will be ilmerged as part of the build.

Usage

IEmailSystem mailzor;

mailzor.SendMail(
    new TaskNotificationMessage
                {
                    To = "email@domain.com",
                    From = "source@domain.com"
                });

IoC Wireup

Using an Autofac module (or just using this registration code in your composition root) to wire up the dependencies for the mailzor utility.

builder.RegisterModule(new MailzorModule 
    { 
        TemplatesDirectory = @"..\Templates",
        SmtpServerIp = "127.0.0.1", // your smtp server
        SmtpServerPort = 25
    });

Autofac

public class MailzorModule : Autofac.Module
{
    public string TemplatesDirectory { get; set; }
    public string SmtpServerIp { get; set; }
    public int SmtpServerPort { get; set; }

    protected override void Load(ContainerBuilder builder)
    {
        builder
            .Register(
                c => new FileSystemEmailTemplateContentReader(TemplatesDirectory))
            .As<IEmailTemplateContentReader>();

        builder
            .RegisterType<EmailTemplateEngine>()
            .As<IEmailTemplateEngine>();

        builder
            .Register(
                c => new EmailSender
                    {
                        CreateClientFactory = () 
                            => new SmtpClientWrapper(new SmtpClient(SmtpServerIp, SmtpServerPort))
                    },
                    DefaultFromAddress = "sourceOfEmails@domain.com")
            .As<IEmailSender>();

        builder
            .Register(
                c => new EmailSubsystem(
                    c.Resolve<IEmailTemplateEngine>(), 
                    c.Resolve<IEmailSender>()))
            .As<IEmailSystem>();
    }
}

Change Log

Version 1.0.0.11 - Added operational default email support

Version 1.0.0.10 - Stablised via ilmerge

Version 1.0.0.7 - Operational with some limitations.

Older version

If you tried this prior to 1.0.0.10 there was an issue with incompatible razor versions, more info here.

License

Licensed under the MIT license.

Something went wrong with that request. Please try again.