New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gmail-node-mailer

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gmail-node-mailer

This Node.js package simplifies sending emails using the Gmail API. It wraps the complexity of Google's authentication and email sending process into a few easy-to-use functions.

  • 1.0.51
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Gmail Node Mailer Package

This Node.js package simplifies sending emails using the Gmail API. It wraps the complexity of Google's authentication and email sending process into a few easy-to-use functions.

Features

  • Easy Gmail API authentication using service accounts.
  • Send emails with simple function calls.
  • Includes TypeScript definitions for better development experience.

Installation

```bash npm install gmail-node-mailer ```

Or if you prefer using Yarn:

```bash yarn add gmail-node-mailer ```

Quick Start

First, ensure you have a service account set up in your Google Cloud Project and have downloaded the service account JSON file. Also, make sure the Gmail API is enabled.

Setting Up Environment Variables

Create a `.env` file in your project's root directory and add the following variables:

```plaintext GMAIL_USER=your_email@example.com ```

Replace `your_email@example.com` with the email address of the Google account you wish to send emails from. Ensure this account is associated with your Google Cloud Project and has the Gmail API enabled.

Using the Package

  1. Initialize the Email Client

    Import and call `initializeClient` at the start of your application. This function initializes the Gmail API client using credentials from your service account JSON file and the sender email from your environment variables.

    ```javascript import { initializeClient } from 'gmail-node-mailer';

    const emailClient = await initializeClient(); ```

  2. Send an Email

    Once the client is initialized, you can send emails using the `sendEmail` function.

    ```javascript import { sendEmail } from 'gmail-node-mailer';

    const emailResponse = await sendEmail({ senderEmail: 'your_email@example.com', recipientEmail: 'recipient@example.com', subject: 'Hello World', message: 'This is a test email sent from gmail-node-mailer.' });

    console.log(emailResponse); ```

API Reference

`initializeClient(options?)`

Initializes and returns the Gmail API client.

  • options (optional): An object containing `serviceAccount` and `senderEmail`. If not provided, the package will use the service account JSON file located at `./private/service_account.json` and the `GMAIL_USER` environment variable.

`sendEmail({ senderEmail, recipientEmail, subject, message })`

Sends an email using the initialized Gmail API client.

  • senderEmail: The email address of the sender.
  • recipientEmail: The email address of the recipient.
  • subject: The subject of the email.
  • message: The plain text message body of the email.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements you wish to make.

License

This project is licensed under the MIT License - see the LICENSE file for details.

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc