Parent: [4d4741] (diff)

Child: [8511fc] (diff)

Download this file

emailer.js    98 lines (85 with data), 2.3 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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*made by Miguel Rodrigues @ KBZ miguel.rodrigues@knowledgebiz.pt*/
//Emailer to to send Notification by Email
var email = require('nodemailer');
var emailconfig = require('../config/email');
var emailbody = require('../signature');
var logger = require('../config/logger.js');
var handler = "backend.controllers.emailer";
var transporter= email.createTransport({
service: "gmail",
auth: {
//type: 'OAuth2',
user: emailconfig.userEmail,
pass: emailconfig.userPwd
}
});
/*
description: Sends an email using the email setup
input:
emailTo: String Array of email destinations ex: ["destination1@email.com","destination2@email.com"]
notification: String with the email body
*/
module.exports.sendEmail = function (emailTo,notification) {
//var destinations = "'";
/*
var destinations ="";
for(i=0;i<emailTo.length;i++){
destinations += emailTo[i];
if(i<emailTo.length-1 && emailTo.length != 1){
destinations += ", "
}
}
*/
/*
if(emailTo.length != 1){
destinations += "'";
}
*/
var mailOptions={
from: emailconfig.userEmail,
//bcc: destinations,
bcc: emailTo,
subject: 'New notification!',
html: '<h4>'+notification+'</h4>'+emailbody.signature
};
logger.debug("sendEmail","Recipients",mailOptions);
transporter.sendMail(mailOptions, function(error,info){
if(error){
logger.error(handler, error);
} else {
logger.info(handler, info.response);
}
});
}
module.exports.sendEmailToken = function (emailTo,token) {
var mailOptions={
from: emailconfig.userEmail,
to: emailTo,
subject: 'New Token!',
html: '<h4>vApp Token for Notification Enabler: <br><br>'+token+'</h4>'+emailbody.signature
};
transporter.sendMail(mailOptions, function(error,info){
if(error){
logger.error(handler, error);
//console.log(error);
} else {
logger.info(handler, info.response);
//console.log('Email sent: '+ info.response);
}
});
}
module.exports.sendEmailNewRule = function (emailTo,newRule) {
var mailOptions={
from: emailconfig.userEmail,
to: emailTo,
subject: 'Intelligent creation of a new Rule!',
html: '<h4>'+newRule+'<br><br></h4>'+emailbody.signature
};
transporter.sendMail(mailOptions, function(error,info){
if(error){
logger.error(handler, error);
} else {
logger.info(handler, info.response);
}
});
}