Created
September 3, 2023 11:59
-
-
Save Sunny-unik/332bc9be6841b2d9496d06d7e420190a to your computer and use it in GitHub Desktop.
Send mail via gmail SMTP server using nodemailer.
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
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