forked from SumoLogic/dmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_email.js
49 lines (43 loc) · 1.23 KB
/
send_email.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
/*
* dmail
*
* Christian Beedgen (christian@sumologic)
*
* This file is subject to the terms and conditions defined in
* file 'LICENSE', which is part of this source code package.
*/
//
// Send the dmail.
//
var transportSpec = process.argv[2];
var filename = process.argv[3];
var url = process.argv[4];
var dashboardId = process.argv[5];
var sender = process.argv[6];
var receiver = process.argv[7];
var subject = process.argv[8];
var dashboardUrl = url + "/ui/dashboard.html?k=" + dashboardId + "&t=r";
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport(transportSpec);
var uniqueID = "schnitzel" + Date.now();
var mailOptions = {
from: sender,
to: receiver,
subject: subject,
text: dashboardUrl + "\n\n" + 'Please enable HTML in your email client.\n',
html: '<a href="' + dashboardUrl + '">' + dashboardUrl + '</a>' +
'<br><br>' +
'<img src="cid:' + uniqueID + '"/>',
attachments: [{
filename: filename,
path: filename,
cid: uniqueID
}]
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});