forked from qawemlilo/node-ping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailer.js
More file actions
63 lines (53 loc) · 1.33 KB
/
mailer.js
File metadata and controls
63 lines (53 loc) · 1.33 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
/*
Module for sending emails
*/
var nodemailer = require('nodemailer'),
config = require('./config'),
mailer;
/*
Mailer function
@param - (Object) opts - mailing options
@param - (Function) fn - callback function
*/
mailer = function (opts, fn) {
var mailOpts, smtpTrans;
// nodemailer configuration
try {
smtpTrans = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: config.GmailAuth.email,
pass: config.GmailAuth.password
}
});
}
catch (err) {
fn('Nodemailer could not create Transport', '');
return;
}
// mailing options
mailOpts = {
from: opts.from,
replyTo: opts.from,
to: opts.to,
subject: opts.subject,
html: opts.body
};
// Send maail
try {
smtpTrans.sendMail(mailOpts, function (error, response) {
//if sending fails
if (error) {
fn(true, error);
}
//Yay!! message sent
else {
fn(false, response.message);
}
});
}
catch (err) {
fn('Nodemailer could not send Mail', '');
}
};
module.exports = mailer;