https://github.com/maxgalbu/nodemailer-plugin-file2inline
https://github.com/maxgalbu/nodemailer-plugin-file2inline
attachment cid html inline node nodemailer-plugin
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/maxgalbu/nodemailer-plugin-file2inline
- Owner: maxgalbu
- License: mit
- Created: 2017-08-24T09:05:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T10:41:29.000Z (almost 9 years ago)
- Last Synced: 2025-09-21T23:51:58.053Z (10 months ago)
- Topics: attachment, cid, html, inline, node, nodemailer-plugin
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nodemailer plugin for converting external images to email attachments
This plugin will convert external images in your [nodemailer](https://github.com/nodemailer/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:

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
#### 1. Load the `nodemailer-plugin-file2inline` plugin:
```javascript
var file2InlinePlugin = require('nodemailer-plugin-file2inline');
```
#### 2. Attach it as a 'compile' handler for a nodemailer transport object
```javascript
//Without options
nodemailerTransport.use('compile', file2InlinePlugin())
//With options
nodemailerTransport.use('compile', file2InlinePlugin({
cidPrefix: "prefix_",
htmlFilePath: "path/relative/to/the/html/file",
maxWidth: 600
))
```
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
```javascript
var nodemailer = require('nodemailer');
var file2InlinePlugin = require('nodemailer-plugin-file2inline');
let transporter = nodemailer.createTransport({
sendmail: true,
newline: 'unix',
});
transporter.use('compile', file2InlinePlugin({cidPrefix: 'somePrefix_'}));
transporter.sendMail({
from: 'me@example.com',
to: 'hello@mixmax.com',
html: '
'
});
```
## Changelog
* 1.0.0 Initial release
## References
1 It might be useful for reply email processing, example with [MailParser](https://github.com/andris9/mailparser)
```javascript
mp.on("attachment", function(attachment, mail){
if (!attachment.contentId.includes('somePrefix')) { // process only images attached by user in reply
// ...
}
});
```
## License
**MIT**