Skip to content

Commit

Permalink
feat(instructions): add instructions for adonis install
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 24, 2017
1 parent 94b20f2 commit 83cc8d0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
61 changes: 61 additions & 0 deletions examples/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict'

const Env = use('Env')

module.exports = {
/*
|--------------------------------------------------------------------------
| Connection
|--------------------------------------------------------------------------
|
| Connection to be used for sending emails. Each connection needs to
| define a driver too.
|
*/
connection: Env.get('MAIL_CONNECTION', 'smtp'),

/*
|--------------------------------------------------------------------------
| SMTP
|--------------------------------------------------------------------------
|
| Here we define configuration for sending emails via SMTP.
|
*/
smtp: {
driver: 'smtp',
pool: true,
port: 2525,
host: '',
secure: false,
auth: {
user: Env.get('MAIL_USERNAME'),
pass: Env.get('MAIL_PASSWORD')
},
maxConnections: 5,
maxMessages: 100,
rateLimit: 10
},

/*
|--------------------------------------------------------------------------
| SparkPost
|--------------------------------------------------------------------------
|
| Here we define configuration for spark post. Extra options can be defined
| inside the `extra` object.
|
| https://developer.sparkpost.com/api/transmissions.html#header-options-attributes
|
| extras: {
| campaign_id: 'sparkpost campaign id',
| options: { // sparkpost options }
| }
|
*/
sparkpost: {
driver: 'sparkpost',
apiKey: Env.get('SPARKPOST_API_KEY'),
extras: {}
}
}
21 changes: 21 additions & 0 deletions instructions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

/*
* adonis-mail
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const path = require('path')

module.exports = async (cli) => {
try {
await cli.copy(path.join(__dirname, 'examples/config.js'), path.join(cli.helpers.configPath(), 'mail.js'))
cli.command.completed('create', 'config/mail.js')
} catch (error) {
console.log(error)
}
}
28 changes: 28 additions & 0 deletions instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Registering provider

The provider is registered inside `start/app.js` file under `providers` array.

```js
const providers = [
'@adonisjs/mail/providers/MailProvider'
]
```

That's all! Now you can use the mail provider as follows.

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

await Mail.send('emails.welcome', {}, (message) => {
message.from('foo@bar.com')
message.to('bar@baz.com')
})
```

The `welcome` is the view name stored inside the `resources/views/emails` directory.

## Configuration and Environment variables

The configuration file is saved as `config/mail.js`, feel free to tweak it according.

Also make sure to define sensitive driver details inside the `.env` file and reference them via `Env` provider.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"bin"
]
},
"standard": {
"globals": ["use"]
},
"dependencies": {
"@adonisjs/generic-exceptions": "^1.0.0",
"debug": "^3.0.0",
Expand Down

0 comments on commit 83cc8d0

Please sign in to comment.