GithubHelp home page GithubHelp logo

xr0master / gmail-nodemailer-transport Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 301 KB

With the help of the Gmail API it is possible to use the send scope and Nodemailer v4+

License: MIT License

TypeScript 97.85% JavaScript 2.15%

gmail-nodemailer-transport's Introduction

gmail-nodemailer-transport

Intro

The custom transport plugin that allows to send email using Nodemailer via Gmail

Why?

With the help of the Gmail API it is possible to use the send scope and Nodemailer v4+. The plugin is very small, optimized and written in TypeScript

Support the project

If you like to use this module please click the star button - it is very motivating.

Quick Start

Install gmail-nodemailer-transport using npm:

$ npm install gmail-nodemailer-transport --save

Documentation

Nodemailer common fields are supported and replyTo

Examples

send the simple email by the access token

  'use strict';
  const nodemailer = require('nodemailer');
  const GmailTransport = require('gmail-nodemailer-transport');

  let transporter = nodemailer.createTransport(new GmailTransport({
    userId: '[email protected]',
    auth: {
      accessToken: 'ya29.Glv5BvE5y-access-token'
    }
  }));

  transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    replyTo: '[email protected]',
    subject: 'Gmail Transport',
    text: 'This is text content'
  }).then((info) => {
    console.log('SUCCESS');
  }).catch((error) => {
    console.log('Something is wrong');
  });

send the simple email, if it's failed to refresh the access token

  'use strict';
  const nodemailer = require('nodemailer');
  const GmailTransport = require('gmail-nodemailer-transport');

  let transporter = nodemailer.createTransport(new GmailTransport({
    userId: '[email protected]',
    auth: {
      clientId: 'clien-id.apps.googleusercontent.com',
      clientSecret: 'clint-secret',
      refreshToken: '1/EAATBaMn-refresh-token',
      accessToken: 'ya29.Glv5BvE5y-access-token'
    }
  }));

  transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    replyTo: '[email protected]',
    subject: 'Gmail Transport',
    text: 'This is text content'
  }).then((info) => {
    console.log('SUCCESS');
  }).catch((error) => {
    console.log('Something is wrong');
  });

send an attachment and embed it to the content

  'use strict';
  const nodemailer = require('nodemailer');
  const GmailTransport = require('gmail-nodemailer-transport');

  let transporter = nodemailer.createTransport(new GmailTransport({
    userId: '[email protected]',
    auth: {
      accessToken: 'ya29.Glv5BvE5y-access-token'
    }
  }));

  transporter.sendMail({
    from: '[email protected]',
    to: '[email protected]',
    replyTo: '[email protected]',
    subject: 'Gmail Transport',
    html: '<!DOCTYPE html><html><body><img src="cid:attachment" alt="attachment"></body></html>',
    attachments: [{
      content: '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAA...', // base64 content
      cid: 'attachment',
      contentType: 'image/jpeg',
      filename: 'attachment.jpg',
      encoding: 'base64'
    }]
  }).then((info) => {
    console.log('SUCCESS');
  }).catch((error) => {
    console.log('Something is wrong');
  });

License

MIT

gmail-nodemailer-transport's People

Contributors

xr0master avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yargevad

gmail-nodemailer-transport's Issues

GmailTransport is not a constructor

       const GmailTransport = require('gmail-nodemailer-transport');
        let transporter = nodemailer.createTransport(new GmailTransport({
            userId: email,
            auth: {
                accessToken: accessToken
            }
        }));

TypeError: GmailTransport is not a constructor

A few questions on oauth scope

Hey,

Thank you for making this, you have no idea how helpful it is; thank you.

I have a couple of questions:

  • What scopes do we need to ask the google for?
  • Any recommendation on a react/nextjs oauth library to fetch the access and refresh token?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.