A Nodemailer plugin for inlining CSS
npm install @point-hub/nodemailer-inlinecss@point-hub/nodemailer-inlinecss is an ESM-only module - you are not able to import it with require().Install from npm
npm install @point-hub/nodemailer-inlinecss
javascript
import { createTransport } from "nodemailer";
import { PluginFunction } from "nodemailer/lib/mailer";
import inlineCss from "@point-hub/nodemailer-inlinecss";var transporter = nodemailer.createTransport();
transporter.use('compile', inlineCss() as PluginFunction);
transporter.sendMail({
from: '...',
to: '...',
html: '
Hello world'
});
`Will result in an email with the following HTML:
Hello world$3
`javascript
import fs from "fs";
import { createTransport } from "nodemailer";
import { PluginFunction } from "nodemailer/lib/mailer";
import inlineCss from "@point-hub/nodemailer-inlinecss";var transporter = nodemailer.createTransport();
transporter.use('compile', inlineCss({
extraCss: fs.readFileSync("./src/styles.min.css").toString(),
}) as PluginFunction);
transporter.sendMail({
from: '...',
to: '...',
html: '
Hello world'
});
`
Your external css file.`css
div {
color: black;
}
``Will result in an email with the following HTML: