Tianhe Gao

通过 nodemailer 发送邮件

https://nodemailer.com/about/

代码:

 1// https://nodemailer.com/smtp/
 2
 3const nodemailer = require("nodemailer");
 4
 5// async..await is not allowed in global scope, must use a wrapper
 6async function main() {
 7  // create reusable transporter object using the default SMTP transport
 8  let transporter = nodemailer.createTransport({
 9    host: "smtp.domain.com",
10    port: 587,
11    secure: false, // true for 465, false for other ports
12    auth: {
13      user: "smtp_email",
14      pass: "smtp_email_credential",
15    },
16  });
17
18  // send mail with defined transport object
19  let info = await transporter.sendMail({
20    from: '"tianheg" <me@example.com>', // sender address
21    to: "", // list of receivers
22    subject: "Hello ✔", // Subject line
23    text: "Hello world?", // plain text body
24    html: "<b>Hello world?</b>", // html body
25  });
26
27  console.log("Message sent: %s", info.messageId);
28  // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
29}
30
31main().catch(console.error);

No notes link to this note

Welcome to tell me your thoughts via "email"
UP