"use strict"; const nodemailer = require("nodemailer"); let DEFAULT_DATA = { //from: '通知', // from: 'PCOLORING', from: "Monitor", to: "chengen@jccy-tech.com", // list of receivers subject: "无标题", text: "无内容", // plain text body //html: "Hello world?", // html body }; async function send(mail) { let transporter = nodemailer.createTransport({ // host: 'mail.ikamaza.com', // 废弃 host: "mail.kizimail.com", port: 587, secure: false, // true for 465, false for other ports auth: { // user: 'mailer', // generated ethereal user // pass: 'Mailer@Jccy2017.', // generated ethereal password user: "pcoloring@kizimail.com", // generated ethereal user pass: "0,k)Mf25T#AX3*=", // generated ethereal password }, }); let data = JSON.parse(JSON.stringify(DEFAULT_DATA)); data = Object.assign(data, mail); try { let info = await transporter.sendMail(data); console.log("Mail", data); console.log("Message sent: %s", info.messageId); // Message sent: // Preview only available when sending through an Ethereal account console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); return info; } catch (err) { console.error(err); } } module.exports = { send, }; if (require.main == module) { send({ to: "guoziyun@jccy-tech.com", subject: "hello:" + new Date(), text: "hello new", //attachments: [{ // path: './mail.js', //}] }) .then(console.log) .catch(console.error); }