1.0.1 • Published 5 years ago

@dadi/nodemailer-browser-transport v1.0.1

Weekly downloads
28
License
BSD
Repository
github
Last release
5 years ago

Nodemailer Preview Transport

Preview your Nodemailer emails in your browser (Inspired by Letter Opener).

Coverage Status

Usage

  1. Install via NPM

    $ npm install @dadi/nodemailer-browser-transport
  2. Use it with Nodemailer

    const nodemailer = require('nodemailer')
    const nodemailerBrowser = require('@dadi/nodemailer-browser-transport')
    
    let tmpdir = require('path').join(process.cwd(), 'tmp', 'nodemailer')
    
    let transport = new nodemailerBrowser({
      dir: tmpdir,
      browser: true
    })
    
    let mailer = nodemailer.createTransport(transport)
    
    mailer.sendMail({
        from: 'hello@domain.com',
        to: user.email,
        // cc:'second@domain.com',
        // bcc:'secretagent@company.gov',
        subject: 'Hello',
        text: 'How are you?'
      }, function (err, info) {
        if (err) {
          console.log('Error: ' + err)
        } else {
          console.log('Response: ' + info)
        }
      })
    }

    Any emails sent through the preview transport will be written to the tmpdir and opened in a browser (unless browser is set to false).