1.1.0 • Published 6 years ago

adonis-mail-notification-channel v1.1.0

Weekly downloads
17
License
MIT
Repository
github
Last release
6 years ago

Adonis Mail Notification Channel

Mail Notification Channel for adonis-notifications.

Build Status Coverage Status

Installation

  1. Add package:
$ npm i adonis-mail-notification-channel --save

or

$ yarn add adonis-mail-notification-channel
  1. Configure mail package.

See mail doc for more information

  1. Register provider inside the your start/app.js file.
const providers = [
  ...
  'adonis-mail-notification-channel/providers/MailNotificationChannelProvider',
  ...
]

Usage example

// app/Model/User.js
const Lucid = use('Lucid')

class User extends Lucid {
  static get traits () {
    return [
      '@provider:Notifiable'
    ]
  }

  /**
   *  // email
   *  foo@bar.com
   *
   *  // email + name
   *  { address: foo@bar.com', name: 'Foo' }
   *
   *  // Array
   *  [{ address: 'foo@bar.com', name: 'Foo' }]
   */
  routeNotificationForEmail () {
    return this.email
  }
}

module.exports = User
// app/Notifications/MyNotification.js
const MailMessage = use('MailMessage')

class MyNotification {
  constructor (text) {
    this.text = text
  }

  via () {
    return ['mail']
  }

  toMail () {
    const message = new MailMessage()
    // You can set up configuration in message
    message
      .configure({
        connection: 'smtp',
        smtp: {
          driver: 'smtp',
          host: process.env.SMTP_HOST,
          port: process.env.SMTP_PORT,
          auth: {
            user: process.env.MAIL_USERNAME,
            pass: process.env.MAIL_PASSWORD
          }
        }
      })
    message
      .text(this.text)
      .subject('Message Notification Channel Test')
    return message
  }
}

module.exports = MyNotification
const Notifications = use('Notifications')

...
const users = await User.all()

await Notifications.send(users, new MyNotification(`It's works!!!`))
...

Credits

Support

Having trouble? Open an issue!

License

The MIT License (MIT). Please see License File for more information.