Skip to content

Instantly share code, notes, and snippets.

@rbk
Created December 30, 2024 20:43
Show Gist options
  • Save rbk/fc16b1c2cf63c3118ed6176d4b07d709 to your computer and use it in GitHub Desktop.
Save rbk/fc16b1c2cf63c3118ed6176d4b07d709 to your computer and use it in GitHub Desktop.
send an email with node mailer
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;
}
@rbk
Copy link
Author

rbk commented Dec 30, 2024

usage:

await sendEmail({
    to: ['[email protected]'],
    from: '[email protected]',
    message: 'sup'
})

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