![]() |
VOOZH | about |
dotnet add package PreMailer.Net --version 2.7.3
NuGet\Install-Package PreMailer.Net -Version 2.7.3
<PackageReference Include="PreMailer.Net" Version="2.7.3" />
<PackageVersion Include="PreMailer.Net" Version="2.7.3" />Directory.Packages.props
<PackageReference Include="PreMailer.Net" />Project file
paket add PreMailer.Net --version 2.7.3
#r "nuget: PreMailer.Net, 2.7.3"
#:package PreMailer.Net@2.7.3
#addin nuget:?package=PreMailer.Net&version=2.7.3Install as a Cake Addin
#tool nuget:?package=PreMailer.Net&version=2.7.3Install as a Cake Tool
C# Library for moving CSS to inline style attributes, to gain maximum E-mail client compatibility.
PreMailer classstring 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.
PreMailer instancestring htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");
var pm = new PreMailer(htmlSource);
// Optional to add analytics tags
pm.AddAnalyticsTags(source, medium, campaign, content, domain = null);
var result = pm.MoveCssInline(
removeStyleElements: false,
ignoreElements: "#ignore",
preserveMediaQueries: true
);
result.Html // Resultant HTML, with CSS in-lined.
result.Warnings // List<string> of any warnings that occurred during processing.
The following options can be passed to the PreMailer.MoveCssInline method to configure its behavior:
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.customFormatter(IMarkupFormatter = null) - Custom formatter to use for the HTML output.preserveMediaQueries(bool = false) - If true and removeStyleElements is true, it will preserve media queries in the style node while removing other CSS, instead of removing the entire style node.useEmailFormatter(bool = false) - If true, empty HTML tags will be preserved as full tags instead of being converted to self-closing tags, and HTML entities like © will be preserved.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.
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");
Alternatively, you can use the preserveMediaQueries parameter to keep your media queries while removing other styles:
var result = PreMailer.MoveCssInline(input, removeStyleElements: true, preserveMediaQueries: true);
And your mobile specific style block should have an ID of ignore:
<style type="text/css" id="ignore">.target { width: 1337px; }</style>
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">
The AddAnalyticsTags method can be used to add Google Analytics tracking parameters to links in your HTML:
var pm = new PreMailer(htmlSource);
pm.AddAnalyticsTags(
source: "newsletter", // utm_source parameter
medium: "email", // utm_medium parameter
campaign: "summer_sale", // utm_campaign parameter
content: "logo_link", // utm_content parameter
domain: "example.com" // Optional: only add tags to links matching this domain
);
This will append ?utm_source=newsletter&utm_medium=email&utm_campaign=summer_sale&utm_content=logo_link to all links, or to links matching the specified domain if provided.
The Document property provides access to the underlying IHtmlDocument object, allowing you to perform custom DOM manipulation before inlining CSS:
using(var pm = new PreMailer(html)){
var document = pm.Document;
// Use AngleSharp to process document before moving css inline...
var result = pm.MoveCssInline();
}
This is useful for advanced scenarios where you need to modify the HTML structure before applying CSS.
InlineResult.Warnings collection.NuGet: PreMailer.Net
Run locally using act:
act push --container-architecture=linux/arm64 --platform ubuntu-slim=node:lts-bullseye
PreMailer.Net is available under the MIT license. See the LICENSE file for more info.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 is compatible. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on PreMailer.Net:
| Package | Downloads |
|---|---|
|
Kentico.Xperience.Libraries
The runtime assemblies for libraries and applications that use Kentico Xperience API. |
|
|
ImmediaC.SimpleCms
ASP.NET Core based CMS |
|
|
ActionMailerNext
Package Description |
|
|
evernote-cloud-sdk-windows
Evernote Cloud SDK for Windows |
|
|
FenixAlliance.ACL.SDK
Application Component for the Alliance Business Suite. |
Showing the top 6 popular GitHub repositories that depend on PreMailer.Net:
| Repository | Stars |
|---|---|
|
smartstore/SmartStoreNET
Open Source ASP.NET MVC Enterprise eCommerce Shopping Cart Solution
|
|
|
smartstore/Smartstore
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 10
|
|
|
SparkDevNetwork/Rock
An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
|
|
|
TerribleDev/OwinOAuthProviders
OAuth providers for Owin
|
|
|
CervantesSec/cervantes
Cervantes is an open-source, collaborative platform designed specifically for pentesters and red teams. It serves as a comprehensive management tool, streamlining the organization of projects, clients, vulnerabilities, and reports in a single, centralized location.
|
|
|
DigitalRuby/MailDemon
Smtp server for mass emailing, managing email lists and more. Built on .NET Core. Linux, MAC and Windows compatible.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.7.3 | 4,270 | 6/16/2026 |
| 2.7.2 | 1,107,034 | 6/27/2025 |
| 2.7.1 | 8,696 | 6/26/2025 |
| 2.7.0 | 74,156 | 6/5/2025 |
| 2.6.0 | 1,588,469 | 5/22/2024 |
| 2.5.0 | 598,082 | 11/24/2023 |
| 2.4.0 | 4,631,263 | 11/2/2021 |
| 2.3.0 | 98,954 | 10/8/2021 |
| 2.2.0 | 3,999,379 | 4/8/2020 |
| 2.1.3 | 621,422 | 10/30/2019 |
| 2.1.1 | 91,814 | 9/16/2019 |
| 2.1.0 | 106,045 | 9/6/2019 |
| 2.0.1 | 716,548 | 12/7/2018 |
| 2.0.0 | 1,018,455 | 7/18/2018 |
| 2.0.0-beta2 | 100,001 | 3/21/2017 |
| 2.0.0-beta1 | 3,333 | 3/21/2017 |
| 1.5.5 | 1,190,861 | 11/7/2016 |
| 1.5.4 | 167,054 | 8/2/2016 |
| 1.5.3 | 92,497 | 4/15/2016 |
| 1.5.2 | 34,841 | 4/12/2016 |
## What's Changed
* Upgrade CI to .NET 10 by @martinnormark in https://github.com/milkshakesoftware/PreMailer.Net/pull/446
* Bump AngleSharp from 1.1.0 to 1.4.0 by @dependabot[bot] in https://github.com/milkshakesoftware/PreMailer.Net/pull/447
* Fix binary compatibility issue with MoveCssInline method signatures in https://github.com/milkshakesoftware/PreMailer.Net/pull/435
* Bump AngleSharp from 1.4.0 to 1.5.0 by @dependabot[bot] in https://github.com/milkshakesoftware/PreMailer.Net/pull/459
* Bump AngleSharp from 1.5.0 to 1.5.1 by @dependabot[bot] in https://github.com/milkshakesoftware/PreMailer.Net/pull/461
## New Contributors
* @Copilot made their first contribution in https://github.com/milkshakesoftware/PreMailer.Net/pull/435
**Full Changelog**: https://github.com/milkshakesoftware/PreMailer.Net/compare/v2.7.2...v2.7.3