-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendMail.js
36 lines (33 loc) · 926 Bytes
/
sendMail.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
/**
* 用 nodemailer API 发送邮件
* @author TingGe<[email protected]>
*/
const config = require("./mailConfig.json");
exports = module.exports = function(
recipient = { mail: "", name: "" },
subject = "",
text = "",
attachments = [],
callback = function() {}
) {
const nodeMailer = require("nodemailer");
const smtpTransport = require("nodemailer-smtp-transport");
/** 1. 创建 */
let transporter = nodeMailer.createTransport(smtpTransport(config));
/** 2. 邮件信息 */
let defaultOptions = {
from: config.auth.user,
to: recipient.mail,
subject,
text: `Hello ${recipient.name}:
${text}`,
// html: "<p> 这是一封用 nodejs 的 nodemailer 发送的测试邮件。</p>",
attachments
};
/** 3. 发送邮件 */
transporter.send = defaultOptions => {
transporter.sendMail(defaultOptions, callback);
return;
};
transporter.send(defaultOptions);
};