forked from high-u/node-red-contrib-simple-sendmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-sendmail.js
29 lines (29 loc) · 960 Bytes
/
simple-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
module.exports = function(RED) {
function SimpleSendmail(config) {
var nodemailer = require("nodemailer");
RED.nodes.createNode(this, config);
var node = this;
node.on("input", function(msg) {
node.status({ fill: "blue", shape: "dot", text: "sending..." });
try {
var transporter = nodemailer.createTransport(msg.mail.transport);
var mailOptions = msg.mail.options;
transporter.sendMail(mailOptions, function(error, info){
if(error){
node.status({ fill: "red", shape: "dot", text: "error" });
node.error(error.message,error);
}else{
msg.payload = info;
node.status({});
node.send(msg);
}
});
}
catch (e) {
node.status({ fill: "red", shape: "dot", text: "error" });
node.error("Cant Send Mail",e);
}
});
}
RED.nodes.registerType("simple-sendmail", SimpleSendmail);
}