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

send-gmail

v1.1.1

Published

Send email through gmail

Downloads

8

Readme

send-gmail

A very simple Node module with one purpose: to send email through the gmail API. This module simply formats the email message and makes basic API requests through the gmail API. For a more robust email solution, check out Nodemailer

send-gmail is a tiny module, requires no dependancies, and is a very simple solution to send an email from a Node server using the gmail API.

Enabling API and Obtaining OAuth Credentials

Please Note that the Google API has changed slightly, but the method below still works. The steps look a little different, especially with regard to the OAuth playground, but the idea is still the same.

To use this module, enable the Gmail API with appropriate permissions. To do this, first visit the Google Cloud Platform, making sure you are logged in with the Google account for which you want to enable the API. Create a new project if you don't already have one, then, in the Dashboard for your project, enable the Gmail API. From there, you will create new credentials of type Oauth client ID. For the Application Type, choose Web Application and add https://developers.google.com/oauthplayground as an Authorized redirect URI. Once the credentials have been created, you should have a Client ID and Client Secret.

Now you just need to exchange the credentials for an initial access token, which can easily be done through the OAuth 2.0 Playground. Click on the settings/cog icon, select "Use your own OAuth credentials," and enter your Client ID and Client Secret. Then, in the list of APIs to enable (on the left side of the page), select and authorize https://mail.google.com under "Gmail API v1." You will need to complete and allow the authorization process through your google account when prompted. Finally, you can click "Exchange authorisation code for tokens," which will get you your initial Authorization Token and your Refresh Token.

There is a good (although somewhat outdated) answer on StackOverflow that walks through this process pretty well with screenshots (some screens have since changed a little).

You will need the resulting credentials which will be passed to send-gmail as an object in the following form:

{
    "clientID": "yourClientID",
    "clientSecret": "yourClientSecret",
    "accessToken": "yourAccessToken",
    "refreshToken": "yourRefreshToken"
}

Using the send-gmail Module

To use this module, first install it with npm install send-gmail. Then, in your application, require it with, for example: const sendEmail = require('send-gmail').

Finally, to send email, call await sendEmail(credentials, to, from, subject, message, contentType, errHandler), where credentials is the path credentials object described above. The parameters, to, from, subject, and message are strings contining the relevant email information. errHandler is an optional callback function to handle any errors (if not specified, errors will be logged to console.log()). contentType is the content type for the email message - this can be text/plain, text/html, or any other supported content type (contentType defaults to text/plain if not specified).