nodemailer-trap-plugin
v4.0.0
Published
Nodemailer plugin to intercept emails in non production environments
Downloads
502
Maintainers
Readme
The Nodemailer plugin to intercept emails for non production environments
Install
Install from npm
npm install nodemailer-trap-plugin --save
Usage
1. Load the trap
function
var trap = require('nodemailer-trap-plugin').trap;
2. Attach it as a 'compile' handler for a nodemailer transport object
nodemailerTransport.use('compile', trap(options))
Where options
- to - the email address used to send emails to. Default:
''
- subject - the subject formatted. Default:
'[DEBUG] - To: {0}, Subject: {1}'
- passthrough - the regex / string / function to passthrough emails without modification (It works only for single recipient). Default:
false
.
Example
var nodemailer = require('nodemailer');
var trap = require('nodemailer-trap-plugin').trap;
var transporter = nodemailer.createTransport();
transporter.use('compile', trap({
to: '[email protected]',
passthrough: '@domain.com'
}));
// first email
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Hello John'
});
// second email
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Hello Jane'
});
The first email has been sent to [email protected]
with subject "[DEBUG] - To: [email protected], Subject: [email protected]"
The second email has been delivered to recipient without modifications because to
field is satisfied options.passthrough
passthrough
String
var nodemailer = require('nodemailer');
var trap = require('nodemailer-trap-plugin').trap;
var transporter = nodemailer.createTransport();
transporter.use('compile', trap({
to: '[email protected]',
passthrough: '@domain.com'
}));
Regex
var nodemailer = require('nodemailer');
var trap = require('nodemailer-trap-plugin').trap;
var transporter = nodemailer.createTransport();
transporter.use('compile', trap({
to: '[email protected]',
passthrough: /.*?@domain\.com/
}));
Function
var nodemailer = require('nodemailer');
var trap = require('nodemailer-trap-plugin').trap;
var transporter = nodemailer.createTransport();
transporter.use('compile', trap({
to: '[email protected]',
passthrough: function (toAddress) {
return toAddress.indexOf('@domain.com') > -1;
}
}));
Release History
See the CHANGELOG.
Contributors
See the list of project's contributors!
License
The MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.