-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmail.js
69 lines (53 loc) · 2.03 KB
/
sendmail.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//nodemail/examples/example_direct.js (find file on GitHub)
var nodemailer = require('nodemailer');
// Create a Direct transport object
var transport = nodemailer.createTransport("Direct", {debug: true});
console.log('Direct transport configured');
// Message object
var message = {
// sender info
from: 'Sender Name <[email protected]>',
// Comma separated list of recipients
to: '"Receiver Name" <[email protected]>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
// plaintext body
text: 'Hello to myself!',
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
// An array of attachments
attachments:[
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
cid: 'note@node' // should be as unique as possible
},
// File Stream attachment
{
fileName: 'nyan cat ✔.gif',
filePath: __dirname+"/nyan.gif",
cid: 'nyan@node' // should be as unique as possible
}
]
};
console.log('Sending Mail');
transport.sendMail(message, function(error, response){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}else{
console.log(response);
console.log('Message sent successfully!');
}
});