Code Monkey home page Code Monkey logo

gmail-send's Introduction

npm version Build Status Coverage Status Code Climate Inch CI

Dependency Status devDependency Status

gmail-send

Minimalistic module to send emails using GMail

Basically it's a wrapper around nodemailer package to simplify its usage for GMail accounts even more.

If you have different needs regarding the functionality, please add a feature request.

Install

npm install --save gmail-send

Usage

Preparational step: Configure application-specific passwords for your GMail account

To be able send emails using GMail from any application (including Node.js) you need to generate application-specific password to access GMail: My Account -> Sign-in & security -> Signing in to Google -> App passwords

Select 'Other (Custom name)' in 'Select app'/'Select device' drop-downs, enter descriptive name for your application and device and press 'GENERATE'. Copy provided password.

Code example

Example 1

console.log('* [example1] sending test email');

// Require the module and set default options
// You may use almost any option available in nodemailer, 
// but if you need fine tuning I'd recommend to consider using nodemailer directly.
var send = require('gmail-send')({
  user: '[email protected]',               // Your GMail account used to send emails
  pass: 'abcdefghijklmnop',             // Application-specific password
  to:   '"User" <[email protected]>',      // Send back to yourself
  // from:   '"User" <[email protected]>'  // from: by default equals to user
  // replyTo:'[email protected]'           // replyTo: by default undefined
  subject: 'test subject',
  text:    'test text'
  // html:    '<b>html text text</b>'
});

var file = './demo-attachment.txt';        // File to attach

// Override any default option and send email
send({                         
  subject: 'attached '+file,   // Override value set as default 
  files: [file]                // String or array of strings of filenames to attach
}, function (err, res) {
  console.log('* [example1] send(): err:', err, '; res:', res);
});

Example 2

You may also set all needed parameters at once and immediately send:

console.log('* [example2] sending test email');

var send = require('gmail-send')({
  user: credentials.user,           // Your GMail account used to send emails
  pass: credentials.pass,           // Application-specific password
  to:   credentials.user,           // Send to yourself
  subject: 'ping',
  text:    'gmail-send example 2'   // Plain text
})();                               // Send without any check

You can find this working examples in ./demo/demo.js (you'll need to set your GMail user/pass in credential.json.example and rename it to credential.json in order to run the example). When credentials are set, run the application using node demo/demo.js or node demo.js depending on your current directory.

Credits

Alexander

Links to package pages:

github.com   npmjs.com   travis-ci.org   coveralls.io   inch-ci.org

License

MIT

gmail-send's People

Contributors

alykoshin avatar

Watchers

 avatar  avatar

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.