Nodemailer plugin for converting external images to email attachments
This plugin will convert external images in your nodemailer email to be inline ("CID-referenced") attachments within the email. Inline attachments are useful because they embed the image inside the actual email, so it's viewable even if the user is checking their email without an internet connection.
Local files will not be accessible with html alone. This Nodemailer plugin will take images in your email html in the form:
<img src="path/to/file.jpg">
and replace it with a CID-referenced attachment that works in all email clients.
Install
yarn add nodemailer-plugin-file2inline
or
npm install nodemailer-plugin-file2inline --save
Usage
nodemailer-plugin-file2inline
plugin:
1. Load the var file2InlinePlugin = ;
2. Attach it as a 'compile' handler for a nodemailer transport object
//Without optionsnodemailerTransport //With optionsnodemailerTransport
Options are:
- cidPrefix: allows to set CID prefix1
{cidPrefix: 'somePrefix_'}
, then all inline images will have prefix in cid, i.e.:cid:somePrefix_5fe3b631c651bdb1
. - htmlFilePath: path to the folder where the html file is, relative to the current working folder
- maxWidth: if this options is set, all images will have the "width" attribute set to the value
Example
var nodemailer = ;var file2InlinePlugin = ; let transporter = nodemailer;transporter;transporter;
Changelog
- 1.0.0 Initial release
References
1 It might be useful for reply email processing, example with MailParser
mp;
License
MIT