GithubHelp home page GithubHelp logo

zahidrasool / mailzor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adrianpell/mailzor

0.0 2.0 0.0 4.5 MB

Using the Razor view engine to create email templates, quickly pluggable into your .NET app.

PowerShell 28.19% Batchfile 1.03% C# 61.99% CSS 8.39% ASP 0.06% JavaScript 0.34%

mailzor's Introduction

mailzor

Build status

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.12

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.ps1 from base folder which will call 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 protected]",
                    From = "[email protected]"
                });

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 = "[email protected]")
			.As<IEmailSender>();

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

Change Log

Version 1.0.0.12 - Deleting temp generated DLLs (issue #4)

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.

mailzor's People

Contributors

nickjosevski avatar miseeger avatar

Watchers

James Cloos avatar Zahid Rasool avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.