comailer
co yield your nodemailer!
Last updated 5 years ago by javascriptismagic .
Unlicense · Bugs · Original npm · Tarball · package.json
$ cnpm install comailer 
SYNC missed versions from official npm registry.

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: 'sender@gmail.com'
        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: 'sender@gmail.com',
        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);
      }
    });

Current Tags

  • 0.1.0                                ...           latest (5 years ago)

2 Versions

  • 0.1.0                                ...           5 years ago
  • 0.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |