-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthMail.js
43 lines (38 loc) · 1.16 KB
/
AuthMail.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
const nodemailer = require('nodemailer')
const generateAuthCode = require('./generateAuthCode')
/*
구글에서는 from 바꾸는 부분 동작하지 않음
참고 : https://nodemailer.com/usage/using-gmail/
*/
async function sendAuthMail(email) {
try {
// SMTP 전송을 위한 transporter 생성
const transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: process.env.AUTH_BOT_MAIL,
pass: process.env.AUTH_BOT_PASS,
},
})
// 이메일 옵션 설정
const code = generateAuthCode()
const mailOptions = {
from: `AuthBot<${noreply}>`,
to: email,
subject: 'The authorization code for model.fit.',
text: `code : ${code}`,
}
// 이메일 전송
const info = await transporter.sendMail(mailOptions)
console.log(`Email sent successfully : ${email}`)
return {
authCode: code,
result: { success: true, code: 'SEND_DONE', errno: 0 },
}
} catch (error) {
console.error(`Email sent failed : ${email}`)
return { success: false, code: error.code, errno: -1 }
}
}
module.exports = sendAuthMail