Skip to content

Instantly share code, notes, and snippets.

@jpalala
Forked from jcollado/email.js
Created May 19, 2026 16:23
Show Gist options
  • Select an option

  • Save jpalala/8c3e566e0c4f2f3df50454d9801cb2ca to your computer and use it in GitHub Desktop.

Select an option

Save jpalala/8c3e566e0c4f2f3df50454d9801cb2ca to your computer and use it in GitHub Desktop.
Send email with nodemailer and AWS SES (API or STMP)
var nodemailer = require('nodemailer');
var sesTransport = require('nodemailer-ses-transport');
var smtpPassword = require('aws-smtp-credentials');
var mailOptions = {
from: 'from@example.com',
to: 'to@example.com',
text: 'This is some text',
html: '<b>This is some HTML</b>',
};
function callback(error, info) {
if (error) {
console.log(error);
} else {
console.log('Message sent: ' + info.response);
}
}
// Send e-mail using AWS SES
mailOptions.subject = 'Nodemailer SES transporter';
var sesTransporter = nodemailer.createTransport(sesTransport({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION
}));
sesTransporter.sendMail(mailOptions, callback);
// Send e-mail using SMTP
mailOptions.subject = 'Nodemailer SMTP transporter';
var smtpTransporter = nodemailer.createTransport({
port: 465,
host: 'email-smtp.us-west-2.amazonaws.com',
secure: true,
auth: {
user: process.env.AWS_ACCESS_KEY_ID,
pass: smtpPassword(process.env.AWS_SECRET_ACCESS_KEY),
},
debug: true
});
smtpTransporter.sendMail(mailOptions, callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment