-
Notifications
You must be signed in to change notification settings - Fork 3
/
mailer.js
58 lines (49 loc) · 1.62 KB
/
mailer.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
var nodemailer = require("nodemailer"),
crypto = require("crypto");
// create reusable transport method (opens pool of SMTP connections)
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: unencryptPassword()
}
});
var Mail = function(from, to, subject, message){
this.from = from;
this.to = to;
this.subject = subject;
this.message = message;
this.getMailOptions = function(){
var mailOptions = {
from: "[email protected]",
replyTo: this.from,
cc: this.from,
to: this.to,
bcc: "[email protected]",
subject: this.subject,
text: this.message,
html: this.message
}
return mailOptions;
}
}
exports.Mail = Mail;
exports.send = function send(mail){
smtpTransport.sendMail(mail.getMailOptions(), function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
smtpTransport.close(); // shut down the connection pool, no more messages
});
}
function unencryptPassword() {
var encrypted_password = "3264e1f83f832ce69c3240b838c56b09";
var password = "AQWZSXEDCRFVTGBYHN";
var decipher = crypto.createDecipher("aes192", password), msg = [];
msg.push(decipher.update(encrypted_password, "hex", "binary"));
msg.push(decipher.final("binary"));
return msg.join("");
}