Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enniel/adonis-mail-notification-channel
https://github.com/enniel/adonis-mail-notification-channel
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/enniel/adonis-mail-notification-channel
- Owner: enniel
- License: mit
- Created: 2018-10-16T09:26:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-18T14:39:13.000Z (over 6 years ago)
- Last Synced: 2024-12-06T17:58:57.484Z (about 2 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
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 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.