通过 nodemailer 发送邮件

https://nodemailer.com/about/

代码:

// https://nodemailer.com/smtp/

const nodemailer = require("nodemailer");

// async..await is not allowed in global scope, must use a wrapper
async function main() {
  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    host: "smtp.domain.com",
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: "smtp_email",
      pass: "smtp_email_credential",
    },
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: '"tianheg" <me@example.com>', // sender address
    to: "", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world?", // plain text body
    html: "<b>Hello world?</b>", // html body
  });

  console.log("Message sent: %s", info.messageId);
  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
}

main().catch(console.error);
欢迎通过「邮件」或者点击「这里」告诉我你的想法
Welcome to tell me your thoughts via "email" or click "here"