npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gmail-node

v1.2.0

Published

It makes Gmail interation easy using Node.js

Downloads

7

Readme

Node GMail Sender

How to get secret key

  • Open link https://console.developers.google.com/flows/enableapi?apiid=gmail
  • Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API.
  • Click Continue, then Go to credentials.
  • At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
  • Select the Credentials tab, click the Create credentials button and select OAuth client ID.
  • Select the application type Other, enter the any name "gmail-node-app", and click the Create button.
  • Click OK to dismiss the resulting dialog.
  • Click the file_download (Download JSON) button to the right of the client ID.
  • Move this file to your working directory and use it with any name like client_secret.json.

Usage

npm install gmail-node --save

Available GMail methods

  • Init GMail:
var gmailNode = require('gmail-node');
var clientSecret = {
    installed: {
        client_id: "k677725446467-6li25pcqgkcllsoh6f6dijcvse64n9pf.apps.googleusercontent.com",
        project_id: "clean-node-119606",
        auth_uri: "https://accounts.google.com/o/oauth2/auth",
        token_uri: "https://accounts.google.com/o/oauth2/token",
        auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
        client_secret: "kF7DvoA_ZrNfa65GnU2zQBgw7",
        redirect_uris: [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
};
gmailNode.init(clientSecret, './token.json', function(err,data){ ... });
  • Send GMail Plain content:
var emailMessage = {
    to: '[email protected]',
    subject: 'Test Subject',
    message: 'Test Email'
};
 gmailNode.send(emailMessage, function (err, data) { ... });
  • Send GMail HTML content:
var emailMessage = {
    to: '[email protected]',
    subject: 'Test Subject',
    message: '<h1>Test Email</h1>'
};
 gmailNode.sendHTML(emailMessage, function (err, data) { ... });
  • Generate URL for Token: Method: generateUrl(): This will return the URL, which user have to open to get code.
gmailNode.generateUrl(clientSecret);
  • Generate Token from code generate from URL Method: generateToken():
gmailNode.generateToken(clientSecret, '4/bZ94wJNeLj4b1nZ0nUhQ7fbqfjIYd4basm_GuG3br2s',(err, data)=>{
    console.log(err || data)
});
  • If you have Token and Credenctial then you can directly use Method: sendWithToken or sendHTMLWithToken No need to call Method: init():
gmailNode.sendWithToken(testMessage, clientSecret, token,function (err, data) {
    console.log(err,data);
});
gmailNode.sendHTMLWithToken(testMessage, clientSecret, token,function (err, data) {
    console.log(err,data);
});
  • Clear GMail Token:
gmailNode.clearToken();

Example

/* Client-Secret Downloaded from Google Development */
var clientSecret = {
    installed: {
        client_id: "k677725446467-6li25pcqgkcllsoh6f6dijcvse64n9pf.apps.googleusercontent.com",
        project_id: "clean-node-119606",
        auth_uri: "https://accounts.google.com/o/oauth2/auth",
        token_uri: "https://accounts.google.com/o/oauth2/token",
        auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
        client_secret: "kF7DvoA_ZrNfa65GnU2zQBgw7",
        redirect_uris: [
            "urn:ietf:wg:oauth:2.0:oob",
            "http://localhost"
        ]
    }
};

var gmailNode = require('gmail-node');

// Message
var testMessage = {
    to: '[email protected]',
    subject: 'Test Subject',
    message: '<h1>Test Email</h1>'
};

// ClientSecret:
gmailNode.init(clientSecret, './token.json', initComplete);

function initComplete(err, dataObject) {
    if(err){
        console.log('Error ', err);
    }else {
        gmailNode.send(testMessage, function (err, data) {
            console.log(err,data);
        });
        
        // OR
        
        gmailNode.sendHTML(testMessage, function (err, data) {
            console.log(err,data);
        });
    }
}

Contribution

It's an open source project, you can report issue and form this repository to create pull request to add features.