nodemailer

2024-08-30 โ€ข 6.9.15

Node.js ็š„้‚ฎไปถๅ‘้€ๅบ“ใ€‚

<!-- ไปฅไธ‹ๆ˜ฏๅŸบไบŽ Koa ็š„ๆกˆๅˆ— -->
const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
  host: "smtp.ethereal.email",
  port: 587,
  secure: false, // true for port 465, false for other ports
  auth: {
    user: "maddison53@ethereal.email",
    pass: "jn7jnAPss4f63QBp6D",
  },
});

// async..await is not allowed in global scope, must use a wrapper
async function main() {
  // send mail with defined transport object
  const info = await transporter.sendMail({
    from: '"Maddison Foo Koch ๐Ÿ‘ป" <maddison53@ethereal.email>', // sender address
    to: "bar@example.com, baz@example.com", // 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: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
}

main().catch(console.error);
npmๅฎ˜็ฝ‘ๆŸฅ็œ‹