trailpack-email

Add a Trails service to sending emails

Usage no npm install needed!

<script type="module">
  import trailpackEmail from 'https://cdn.skypack.dev/trailpack-email';
</script>

README

trailpack-email

Gitter NPM version NPM downloads Build status Dependency Status Code Climate Beerpay Beerpay

:package: Add a Trails service to sending emails

Intallation

With yo :

npm install -g yo generator-trails
yo trails:trailpack trailpack-email

With npm (you will have to create config file manually) :

npm install --save trailpack-email

Configuration

First you need to add this trailpack to your main configuration :

// config/main.js

module.exports = {
   ...

   packs: [
      ...
      require('trailpack-email'),
      ...
   ]
   ...
}

Then:

// config/email.js
module.exports = {
  //Custom transporter object to send email, by default created from smtp values but can be override here
  customTransporter: null,
  
    /*
     * SMTP Configuration
     * @see {@link http://nodemailer.com/2-0-0-beta/setup-smtp/}
     */
    smtp: {
      host: 'smtp.gmail.com',
      port: 465,
      secure: true, // use SSL
      auth: {
        user: 'user@gmail.com',
        pass: 'pass'
      }
    },
    /*
     * Default data use with EmailService.send
     * from, to, css, bcc, subject, text, html, attachments
     */
    defaultData: {
      from: 'noreply@gmail.com'
    }
}

Usage

Now you can send emails like this :

this.app.services.EmailService.send({
      to: 'user@gmail.com',
      subject: 'Test',
      text: 'test',
      html: '<p>test</p>'
    }, (err, info) => {

    })
//Or with Promise
this.app.services.EmailService.send({
      to: 'user@gmail.com',
      subject: 'Test',
      text: 'test',
      html: '<p>test</p>'
    }).then(info => {

    }).catch(err => this.log.error(err))
    

License

MIT

Support on Beerpay

Hey dude! Help me out for a couple of :beers:!

Beerpay Beerpay