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);
@ProximaCentauri1989
Copy link

ProximaCentauri1989 commented Oct 19, 2020

Hello. I'm new in SES. Can you explain me what email accounts can I can use with SES? Does SES provide its own email box? And can I, for example, send emails to gmail accounts? Does this somehow related to an AWS region?

@jcollado
Copy link
Author

@ProximaCentauri1989 It's been a while since I used SES for the last time.

In any case, I believe that you don't have any mailbox in SES, what you need to do is verify that you own the email address you're using as the source:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html

In terms of what email address can you use as destination, you should be able to send emails to any address you like.

@ruucm-working
Copy link

Thanks!

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