Last active
November 13, 2024 13:51
-
-
Save jcollado/cd357d9728b76bd08ff8 to your computer and use it in GitHub Desktop.
Send email with nodemailer and AWS SES (API or STMP)
This file contains 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
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); |
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?
@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.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@VictorMs The code in the example shows how to send an email using the AWS SES service using either the API or the SMTP interface. If you're interested in the SMTP interface, then please have a look at the following links:
https://nodemailer.com/smtp/
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp.html