All Projects → milkshakesoftware → Premailer.net

milkshakesoftware / Premailer.net

Licence: mit
C# library that moves your stylesheets to inline style attributes, for maximum compatibility with E-mail clients.

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Premailer.net

Mosaico
Mosaico - Responsive Email Template Editor
Stars: ✭ 1,392 (+176.74%)
Mutual labels:  email, email-template
Hermes
Golang package that generates clean, responsive HTML e-mails for sending transactional mail
Stars: ✭ 2,379 (+372.96%)
Mutual labels:  email, email-template
Responsive Html Email Template
A free simple responsive HTML email template
Stars: ✭ 10,831 (+2053.28%)
Mutual labels:  email, email-template
Laravel Mail View
Preview Laravel Mailables and notifications in your browser.
Stars: ✭ 41 (-91.85%)
Mutual labels:  email, email-template
email-framework
A simple, gulp powered framework to develop and test responsive emails.
Stars: ✭ 19 (-96.22%)
Mutual labels:  email, email-template
Email Templates
A collection of email templates coded in MJML
Stars: ✭ 69 (-86.28%)
Mutual labels:  email, email-template
Html Email Templates
Free HTML Email Templates created using the Postcards - https://designmodo.com/postcards/
Stars: ✭ 178 (-64.61%)
Mutual labels:  email, email-template
Django mail admin
The one and only django app to receive & send mail with templates and multiple configurations.
Stars: ✭ 140 (-72.17%)
Mutual labels:  email, email-template
bulk-email-sender
Send Templatized Dynamic Emails Automatically
Stars: ✭ 30 (-94.04%)
Mutual labels:  email, email-template
ResetCSS
Reset CSS Stylesheet to reduce browser inconsistencies.
Stars: ✭ 17 (-96.62%)
Mutual labels:  stylesheets, css3
Bojler
Bojler is an email framework
Stars: ✭ 885 (+75.94%)
Mutual labels:  email, email-template
Maizzle Php
Jigsaw-based PHP build system for rapid HTML email development with Tailwind CSS.
Stars: ✭ 303 (-39.76%)
Mutual labels:  email, email-template
Mysigmail
UI Email Signature Generator - Make easy to create your email signature
Stars: ✭ 925 (+83.9%)
Mutual labels:  email, email-template
Pine
A modular and lightweight, responsive email framework.
Stars: ✭ 98 (-80.52%)
Mutual labels:  email, email-template
Cirrus
☁️ The CSS framework for the modern web.
Stars: ✭ 716 (+42.35%)
Mutual labels:  css3, stylesheets
React Email Editor
Drag-n-Drop Email Editor Component for React.js
Stars: ✭ 3,131 (+522.47%)
Mutual labels:  email, email-template
woo-custom-emails
An add-on to support woocommerce custom emails
Stars: ✭ 15 (-97.02%)
Mutual labels:  email, email-template
Cerberus
A few simple, but solid patterns for responsive HTML email templates and newsletters. Even in Outlook and Gmail.
Stars: ✭ 4,356 (+766%)
Mutual labels:  email, email-template
Email Templates
Free HTML email templates for Mailchimp and other emails services
Stars: ✭ 457 (-9.15%)
Mutual labels:  email-template
Salmon
A Python Mail Server
Stars: ✭ 482 (-4.17%)
Mutual labels:  email

PreMailer.Net .NET Core build Nuget count

C# Library for moving CSS to inline style attributes, to gain maximum E-mail client compatibility.

Usage

Static method on PreMailer class

string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");

var result = PreMailer.MoveCssInline(htmlSource);

result.Html 		// Resultant HTML, with CSS in-lined.
result.Warnings 	// string[] of any warnings that occurred during processing.

Set up PreMailer instance

string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");

var pm = new PreMailer(htmlSource);
pm.AddAnalyticsTags(source, medium, campaign, content, domain = null); // Optional to add analytics tags

var result = pm.MoveCssInline(...);

result.Html 		// Resultant HTML, with CSS in-lined.
result.Warnings 	// string[] of any warnings that occurred during processing.

Options

The following options can be passed to the PreMailer.MoveCssInline method to configure it's behaviour:

  • baseUri(Uri = null) - Base URL to apply to link elements with href values ending with .css.
  • removeStyleElements(bool = false) - Removes elements that were used to source CSS (currently, only style is supported).
  • ignoreElements(string = null) - CSS selector of element(s) not to inline. Useful for mobile styles (see below).
  • css(string = null) - A string containing a style-sheet for inlining.
  • stripIdAndClassAttributes(bool = false) - True to strip ID and class attributes.
  • removeComments(bool = false) - True to remove comments, false to leave them intact.

External style sheets

Sometimes it's handy to reference external style sheets with a <link href="..." /> element. PreMailer will download and use external style sheets as long as the value of href ends with .css.

Both absolute and relative URLs are supported. If the URL is relative, you must specify the baseUri parameter in either the constructor, or when calling the static MoveCssInline method.

<link /> elements that match the ignoreElements selector won't be downloaded.

Media queries

If you want to apply mobile styles to your e-mail, you should put your mobile specific styles in its own style block that targets the appropriate devices using media queries.

But since you cannot know by the time of sending an e-mail whether or not it will be viewed on a mobile device, the style block that targets mobile devices should not be inlined!

To ignore a style block, you need to specify an ignore selector when calling the MoveCssInline method, like this:

var result = PreMailer.MoveCssInline(input, false, ignoreElements: "#ignore");

And your mobile specific style block should have an ID of ignore:

<style type="text/css" id="ignore">.target { width: 1337px; }</style>

Premailer specific CSS becomes HTML attributes

Premailer looks for the use of CSS attributes prefixed with -premailer and will proxy the value through to the DOM element as an attribute.

For example

table {
    -premailer-cellspacing: 5;
    -premailer-width: 500;
}

will make a table element render as

<table cellspacing="5" width="500">

Custom DOM Processing

using(var pm = new PreMailer(html)){

  var document = pm.Document;

  // use AngleSharp to process document before moving css inline ...

  var result = pm.MoveCssInline();
}

Notes

  • Pseudo classes/elements which not supported by external dependencies, or doesn't make sense in email, will be ignored and logged to the InlineResult.Warnings collection.

Installation

NuGet: PreMailer.Net

Contributors

Among others

License

PreMailer.Net is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].