forked from nodemailer/nodemailer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin-stream.js
33 lines (28 loc) · 913 Bytes
/
plugin-stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
// This example demonstrates the 'stream' step with a plugin that converts all spaces to tabs
var nodemailer = require('../src/nodemailer');
var transporter = nodemailer.createTransport(require('nodemailer-stub-transport')());
var plugin = new(require('stream').Transform)();
plugin._transform = function(chunk, encoding, done) {
// replace all spaces with tabs in the stream chunk
for (var i = 0; i < chunk.length; i++) {
if (chunk[i] === 0x20) {
chunk[i] = 0x09;
}
}
this.push(chunk);
done();
};
transporter.use('stream', function(mail, callback) {
// apply output transformer to the raw message stream
mail.message.transform(plugin);
callback();
});
transporter.sendMail({
from: 'sender',
to: 'receiver',
subject: 'hello',
text: 'hello world!'
}, function(err, info) {
console.log(info.response.toString());
});