Created
February 3, 2022 15:10
-
-
Save chrispruitt/0b0af7880905ef1696e527a3306d84b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const nodemailer = require("nodemailer"); | |
// async..await is not allowed in global scope, must use a wrapper | |
async function main() { | |
// Generate test SMTP service account from ethereal.email | |
// Only needed if you don't have a real mail account for testing | |
let testAccount = await nodemailer.createTestAccount(); | |
// create reusable transporter object using the default SMTP transport | |
let transporter = nodemailer.createTransport({ | |
host: "smtp.ethereal.email", | |
port: 587, | |
secure: false, // true for 465, false for other ports | |
auth: { | |
user: testAccount.user, // generated ethereal user | |
pass: testAccount.pass, // generated ethereal password | |
}, | |
}); | |
// send mail with defined transport object | |
let info = await transporter.sendMail({ | |
from: '"Fred Foo 👻" <[email protected]>', // sender address | |
to: "[email protected], [email protected]", // 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: <[email protected]> | |
// Preview only available when sending through an Ethereal account | |
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); | |
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... | |
} | |
main().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment