Created
February 26, 2019 00:14
-
-
Save Roverr/9f6564f90dd99424a6bbd3438e5ec3b1 to your computer and use it in GitHub Desktop.
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
const nodemailer = require('nodemailer'); | |
const key = require('./key.json'); | |
// Change this to one of your email addresses in the organisation | |
const YOUR_EMAIL_ADDRESS = 'info@your_company.com'; | |
// Change this to the receiver to the mail | |
const SEND_TO = 'receiver@other_company.com' | |
async function start() { | |
const transporter = nodemailer.createTransport({ | |
host: 'smtp.gmail.com', | |
port: 465, | |
secure: true, | |
auth: { | |
type: 'OAuth2', | |
user: YOUR_EMAIL_ADDRESS, | |
serviceClient: key.client_id, | |
privateKey: key.private_key, | |
}, | |
}); | |
try { | |
await transporter.verify(); | |
await transporter.sendMail({ | |
from: YOUR_EMAIL_ADDRESS, | |
to: SEND_TO, | |
subject: 'John Doe opens new farm YOU GOTTA SEE IT', | |
text: 'It is beautiful.', | |
}); | |
} catch (err) { | |
console.error(err); | |
} | |
} | |
start(); |
Yes, thanks @Roverr! Really invaluable.
Still working as of April 2021 - just with the same observation that @sabasm made regarding the change in Google console.
https://medium.com/@imre_7961/nodemailer-with-g-suite-oauth2-4c86049f778a
Thank you very much for guiding me through the Google maze :) All working perfectly!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
amazing, thank you very much! loved the Medium Post!, up and working everything as 05/17/19, just a little change on google console, saving a step :)