通过 nodemailer 发送邮件

https://nodemailer.com/about/

代码:

 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
// 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@tianhegao.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);





评论和交流请发送邮件到 me@tianhegao.com





通过以下渠道赞赏此文