forked from audreyt/ethercalc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
emailer.js
executable file
·53 lines (53 loc) · 1.55 KB
/
emailer.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
// Generated by LiveScript 1.4.0
(function(){
this.__emailer__ = null;
this.include = function(){
var emailer, nodemailer, generator, smtpTransport;
if (this.__emailer__) {
return this.__emailer__;
}
emailer = {};
emailer.log = function(){
return console.log("email tester");
};
nodemailer = require('nodemailer');
generator = require('xoauth2').createXOAuth2Generator({
user: process.env.gmail_user,
clientId: process.env.gmail_clientId,
clientSecret: process.env.gmail_clientSecret,
refreshToken: process.env.gmail_refreshToken
});
generator.on('token', function(token){});
smtpTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
xoauth2: generator
}
});
emailer.sendemail_ignore = function(emailTo, emailSubject, emailBody, callback){
return callback(" [E-mail Sent]");
};
emailer.sendemail = function(emailTo, emailSubject, emailBody, callback){
var mailOptions;
mailOptions = {
from: process.env.gmail_user,
to: emailTo,
subject: emailSubject,
text: emailBody,
html: emailBody
};
smtpTransport.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
console.dir(info);
callback(" EMAIL ERROR - " + error);
} else {
callback(" [E-mail Sent]");
return info.accepted;
}
smtpTransport.close();
});
};
return this.__emailer__ = emailer;
};
}).call(this);