-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsend-email-utils.js
49 lines (40 loc) · 1.19 KB
/
send-email-utils.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
const email_address = 'your_gmail_address@gmail.com';
const email_password = 'your_gmail_password';
//email
const smtpTransport = require('nodemailer-smtp-transport')
const nodemailer = require('nodemailer');
const moment = require('moment');
exports.sendEmailFnt = function(err, logger, errLogger, title, callback){
//메일 발송 설정
var transporter = nodemailer.createTransport(smtpTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
user: email_address,
pass: email_password
},
tls: { rejectUnauthorized: false }
}));
// 메일 설정
var errMessage = null;
var errStack = null;
if(err && err.message) errMessage = err.message;
if(err && err.stack) errStack = err.stack;
var mailOptions = {
from: 'Hamonia <' + email_address + '>',
to: email_address,
subject: '[' + title + '] ' + errMessage,
text: '['+(moment().format('YYYY-MM-DD HH:mm:ss'))+'] [ERROR] ' + title + ' ' + errStack
};
// 메일 발송
transporter.sendMail(mailOptions, function(error, info){
if (error) {
errLogger.error('[ERROR] email ' + errStack);
} else {
logger.info('Email sent: ' + info.response);
}
if(callback) callback();
});
}