Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/enniel/adonis-mail-notification-channel


https://github.com/enniel/adonis-mail-notification-channel

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Adonis Mail Notification Channel

Mail Notification Channel for [adonis-notifications](https://github.com/enniel/adonis-notifications).

[![Build Status](https://travis-ci.org/enniel/adonis-mail-notification-channel.svg?branch=master)](https://travis-ci.org/enniel/adonis-mail-notification-channel)
[![Coverage Status](https://coveralls.io/repos/github/enniel/adonis-mail-notification-channel/badge.svg?branch=master)](https://coveralls.io/github/enniel/adonis-mail-notification-channel?branch=master)

## Installation

1. Add package:

```bash
$ npm i adonis-mail-notification-channel --save
```
or

```bash
$ yarn add adonis-mail-notification-channel
```

2. Configure mail package.

See [mail doc](https://adonisjs.com/docs/4.1/mail) for more information

3. Register provider inside the your `start/app.js` file.

```js
const providers = [
...
'adonis-mail-notification-channel/providers/MailNotificationChannelProvider',
...
]
```

## Usage example

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

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

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

module.exports = User
```

```js
// 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
```

```js
const Notifications = use('Notifications')

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

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

```

## Credits

- [Evgeni Razumov](https://github.com/enniel)

## Support

Having trouble? [Open an issue](https://github.com/enniel/adonis-mail-notification-channel/issues/new)!

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.