Created
December 30, 2024 20:43
-
-
Save rbk/fc16b1c2cf63c3118ed6176d4b07d709 to your computer and use it in GitHub Desktop.
send an email with node mailer
This file contains hidden or 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
const nodemailer = require('nodemailer'); | |
const sendEmail = async ({to, subject, message, from}) => { | |
const transporter = nodemailer.createTransport({ | |
host: process.env.AWS_SMTP_HOST, | |
port: process.env.AWS_SMTP_PORT, | |
secure: false, | |
auth: { | |
user: process.env.AWS_SMTP_USER, // generated ethereal user | |
pass: process.env.AWS_SMTP_PASS, // generated ethereal password | |
}, | |
tls: { | |
ciphers:'SSLv3' | |
} | |
}); | |
const info = await transporter.sendMail({ | |
from: from ?? process.env.EMAIL_DEFAULT_FROM, // sender address | |
to: to, // list of receivers | |
subject: subject, // Subject line | |
text: message, // plain text body | |
html: message, // html body | |
}); | |
console.log('SMTP sendMail result:', info) | |
return info; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: