Skip to content

Instantly share code, notes, and snippets.

@Thainainan03
Last active December 25, 2019 17:37
Show Gist options
  • Save Thainainan03/40a1b89d19968e4acd63a211a42f8e1c to your computer and use it in GitHub Desktop.
Save Thainainan03/40a1b89d19968e4acd63a211a42f8e1c to your computer and use it in GitHub Desktop.
Mailtrap with nodemailer
const nodemailer = require("nodemailer");
async function main() {
let transporter = nodemailer.createTransport({
host: "smtp.mailtrap.io",
port: 2525,
auth: {
user: "", // SMTP username from mailtrap
pass: "", // SMTP password from mailtrap
}
});
let info = await transporter.sendMail({
from: '"Fred Foo 👻" <foo@example.com>',
to: "bar@example.com, baz@example.com",
subject: "Hello ✔",
html: "<b>Hello world?</b>",
attachments: [{
filename: 'igg-logo.png',
path: 'https://www.igeargeek.com/_nuxt/img/835647d.png'
}]
});
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment