Skip to content

Instantly share code, notes, and snippets.

@jcollado
Last active November 13, 2024 13:51
Show Gist options
  • Save jcollado/cd357d9728b76bd08ff8 to your computer and use it in GitHub Desktop.
Save jcollado/cd357d9728b76bd08ff8 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: '[email protected]',
to: '[email protected]',
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);
@ruucm-working
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment