forked from ux34/daka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.js
38 lines (33 loc) · 967 Bytes
/
mail.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
/**
* @description 邮件发送
* 调用方法:sendMail('[email protected]','这是测试邮件', 'Hi,这是一封测试邮件');
* @fileName mail.js
* @author 伞仙
* @date 2021/07/21 19:05:28
*/
const nodemailer = require("./nodemailer/lib/nodemailer");
const config = {
user: '[email protected]', // 邮箱帐号
pass: 'ctcpzlmlijctbaaj', // 邮箱授权码
from: '"Daka" <[email protected]>', // 发件人 昵称与邮箱
}
let transporter = nodemailer.createTransport({
host: "smtp.qq.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: config.user, // 邮箱账号
pass: config.pass, // 授权码,通过QQ邮箱获取
},
});
function sendMail(to, subject, text) {
transporter.sendMail({
from: config.from,
to: to,
subject: subject,
text: text
})
.then(() => console.log("邮件发送成功"))
.catch((err) => console.log("邮件发送失败, " + err.message))
}
module.exports = sendMail;