Skip to content

Instantly share code, notes, and snippets.

@Wildanzr
Created April 24, 2023 15:27
Show Gist options
  • Save Wildanzr/5885c461615c8d37f8928a72dd5cc4d1 to your computer and use it in GitHub Desktop.
Save Wildanzr/5885c461615c8d37f8928a72dd5cc4d1 to your computer and use it in GitHub Desktop.
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
type: 'OAuth2',
user: OAUTH_EMAIL,
clientId: OAUTH_CLIENT_ID,
clientSecret: OAUTH_CLIENT_SECRET,
refreshToken: OAUTH_REFRESH_TOKEN,
accessToken: accessToken.toString()
}
});
// create mail options
const mailOptions = {
from: OAUTH_EMAIL,
to: '[email protected]',
subject: 'Hello ✔',
text: 'Hello world?',
};
// send mail
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment