-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend-email.js
More file actions
38 lines (33 loc) · 1.26 KB
/
send-email.js
File metadata and controls
38 lines (33 loc) · 1.26 KB
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
module.exports = function(RED) {
function sendEmailNode(config) {
RED.nodes.createNode(this,config);
var node = this;
this.router = RED.nodes.getNode(config.router).router;
if (this.router){
this.on('input', function(msg, send, done) {
node.router.sendEmail(msg.payload.to,msg.payload.subject,msg.payload.body,msg.payload.cc).then((res)=>{
if (res.success === true){
node.status({fill:"green",shape:"dot",text:"sent"});
}else if (res.success === false){
node.status({fill:"red",shape:"ring",text:"send failed"});
}
msg.payload = res;
send(msg);
if (done) {
done();
}
})
.catch((err)=>{
node.status({fill:"red",shape:"ring",text:err.message});
node.error(err);
if (done){
done();
}
})
});
}else{
this.error('No router configuration provided');
}
}
RED.nodes.registerType("send-email",sendEmailNode);
}