Skip to content

Instantly share code, notes, and snippets.

@Sunny-unik
Created September 3, 2023 11:59
Show Gist options
  • Save Sunny-unik/332bc9be6841b2d9496d06d7e420190a to your computer and use it in GitHub Desktop.
Save Sunny-unik/332bc9be6841b2d9496d06d7e420190a to your computer and use it in GitHub Desktop.
Send mail via gmail SMTP server using nodemailer.
import nodemailer from 'nodemailer';
export default function (from, appPassword, to, subject, htmlMsg) {
return new Promise((resolve, reject) => {
const mailOptions = {
from: from,
to: to,
subject: subject,
html: htmlMsg,
};
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: { user: from, pass: appPassword },
});
transporter.sendMail(mailOptions, function (error, info) {
error ? reject(error) : resolve(info);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment