Skip to content

Instantly share code, notes, and snippets.

@Roverr
Created February 26, 2019 00:14
Show Gist options
  • Save Roverr/9f6564f90dd99424a6bbd3438e5ec3b1 to your computer and use it in GitHub Desktop.
Save Roverr/9f6564f90dd99424a6bbd3438e5ec3b1 to your computer and use it in GitHub Desktop.
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();
@sabasm
Copy link

sabasm commented May 17, 2019

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 :)

@benkeen
Copy link

benkeen commented Apr 12, 2021

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

@pvanagtmaal
Copy link

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