-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (49 loc) · 1.26 KB
/
index.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
var email = require('emailjs'),
nconf = require('nconf');
module.exports=
{
SendMail:function(email_add, body, subject, email_from, email_bcc, email_cc, callback)
{
// Get mail server configuration from mail.json config
nconf.argv()
.env()
.add( 'user', {file:process.cwd()+'/mail.json', type: 'file'});
var server = email.server.connect({
user: nconf.get('user'),
password:nconf.get('password'),
host: nconf.get('host'),
ssl: nconf.get('ssl'),
port: nconf.get('port')
});
var mail_from=(email_from)? email_from:nconf.get('noreply_from');
//Build Payload
var payLoad =
{
text: body,
from: mail_from,
to: email_add,
cc: email_cc,
bcc: email_bcc,
subject: subject,
attachment:
[
{data:body,alternative:true}
]
}
payLoad.to = email_add;
// send the message and get a callback with an error or details of the message that was sent
server.send(payLoad, function(err, message)
{
if(err)
{
console.log('Send email error');
callback(err, null);
}
else
{
console.log('Send email success');
callback(null, 'success');
}
});
}
};