adonis-mail-notification-channel
v1.1.0
Published
The Adonis Mail Notification Channel.
Downloads
1
Readme
Adonis Mail Notification Channel
Mail Notification Channel for adonis-notifications.
Installation
- Add package:
$ npm i adonis-mail-notification-channel --save
or
$ yarn add adonis-mail-notification-channel
- Configure mail package.
See mail doc for more information
- 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
* [email protected]
*
* // email + name
* { address: [email protected]', name: 'Foo' }
*
* // Array
* [{ address: '[email protected]', 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.