
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
gmail-sender-oauth
Advanced tools
Send emails with Gmail API using an OAuth2 object
#install and save
npm install gmail-sender-oauth --save
Require the module.
var gmailSender = require('gmail-sender-oauth');
Load Google Api Project client secret. To get this file follow Step 1 .
gmailSender.setClientSecretsFile('./client_secret.json');
Send an email specifying all the headers (i.e 'from', 'to', 'subject', 'body').
var params = {
from: 'sender.oauth@gmail.com',
to: 'sender.oauth@gmail.com',
subject: 'Win an iPhone 7 today!!!',
body: 'This is a test'
};
gmailSender.send(accessToken, params, function (err, resp) {
if (err) {
return console.error('Something went wrong: ' + err);
}
else {
console.log('Message sent with id: ' + resp.id);
}
});
This assumes you already have an access token from Google Api. To get one, see test Generate Access Token and if you need to start from scratch, generate a Server Auth code first, see test Generate Server Auth code .
#Terminal output
~/personal/gmail-sender-oauth/test$ node generate_server_auth.js
Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.compose&response_type=code&client_id=1081826302113-deknk5sgd6n2vutgv3l4ub4530qqc8kh.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob
If you need a accessToken to be generated as well, run:
node generate_access_token <SERVER_AUTH_CODE>, with the code you received from the visited URL.
~/personal/gmail-sender-oauth/test$ node generate_access_token.js 4/AR34xAC0Z437ItI_27FmpDYmCeNMpMWNyZk0G6cV6EQ
token: {"access_token":"ya29.Gls0BCt9gHK7Bmn5mPQFff6JCaVyt8ZcRiUgLPQL4SmAFk-msJOTIaISi-UiPhRD7QHR2n_8dJXymn08helwDCcnHpGK14sqHXhsH3fgTlvaNz1dZbA7P6LJO4BH","refresh_token":"1/kVLTLeR7vb1e6tuT6XHWBqZ0nG-qwldfeO1uhwdwBok","token_type":"Bearer","expiry_date":1492885695675}
FAQs
Send emails with Gmail API using an OAuth2 object
We found that gmail-sender-oauth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.