Skip to content

JavascriptIsMagic/comailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comailer

A simple CO wrapper around Nodemailer

yield Nodemailer from co or koa!

CoffeeScript (is optional, see javascript below)

    'use strict'
    co = require 'co'

    comailer = require 'comailer'
    transporter = comailer.createTransport
      service: 'gmail'
      auth:
        user: '[email protected]'
        pass: 'password'

    co ->
      # yielding can throw errors you could try/catch or bail out
      try

        result = yield transporter.sendMail
          from: 'sender@address'
          to: 'receiver@address'
          subject: 'hello'
          text: 'hello world!'

        console.log result
      catch error
        console.error error.stack

    # if you need to still need to call without yielding:
    thunkOfSendMail = transporter.sendMail
      from: 'sender@address'
      to: 'receiver@address'
      subject: 'hello'
      text: 'hello world!'
    #...
    thunkOfSendMail (error, result) ->
      if error
        console.error error.stack
      else
        console.log result

Javascript

    'use strict'
    var co = require('co');

    var comailer = require('comailer');
    var transporter = comailer.createTransport({
      service: 'gmail',
      auth: {
        user: '[email protected]',
        pass: 'password'
      }
    });

    co(function* () {
      // yielding can throw errors you could try/catch or bail out
      try {

        var result = yield transporter.sendMail({
          from: 'sender@address',
          to: 'receiver@address',
          subject: 'hello',
          text: 'hello world!'
        });

        console.log(result);
      } catch (error) {
        console.error(error.stack);
      }
    });

    // if you need to still need to call without yielding using the returned thunk directly:
    thunkOfSendMail = transporter.sendMail({
      from: 'sender@address',
      to: 'receiver@address',
      subject: 'hello',
      text: 'hello world!'
    });
    //...
    thunkOfSendMail(function (error, result) {
      if (error) {
        console.error(error.stack);
      } else {
        console.log(result);
      }
    });

About

A simple co wrapper around nodemailer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published