Skip to content

Commit

Permalink
feat: add docs for mailtrap (#41)
Browse files Browse the repository at this point in the history
* feat: add Mailtrap to sidebar

* feat: add Mailtrap

* feat: add docs for Mailtrap
  • Loading branch information
DominusKelvin authored Nov 20, 2024
1 parent bc27a9b commit 1be189c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ function mailGuide() {
collapsed: false,
items: [
{ text: 'SMTP', link: 'mail/smtp-transport' },
{ text: 'Mailtrap', link: 'mail/mailtrap-transport' },
{ text: 'Resend', link: 'mail/resend-transport' },
{ text: 'Local Development', link: 'mail/local-development' }
]
Expand Down
2 changes: 1 addition & 1 deletion docs/mail/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ features:
details: Sails Mail provides an amazing and elegant API for sending emails.
- icon: 🚚
title: Multiple transports
details: Supports SMTP, Resend, log, and more transports, to allow you use your favorite email service without any stress.
details: Supports SMTP, Mailtrap, log, and more transports, to allow you use your favorite email service without any stress.
- icon: 🛠️
title: Flexible configuration
details: Need multiple email transports or mailers in the same Sails project? Mail make that a breeze to do.
Expand Down
89 changes: 89 additions & 0 deletions docs/mail/mailtrap-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
head:
- - meta
- property: 'og:image'
content: https://docs.sailscasts.com/sails-mail-social.png
title: Resend Transport
editLink: true
prev:
text: 'SMTP Transport'
link: '/mail/smtp-transport'
next:
text: 'Resend'
link: '/mail/resend-transport'
---

# Mailtrap Transport

To use the [Mailtrap](https://mailtrap.io?utm_source=sails-hook-mail) transport, install `mailtrap` via NPM:

```sh
npm i mailtrap --save
```

Next, setup a mailer in the `mailers` object in `config/mail.js`, the name of the mailer can be anything but you can use `mailtrap` as well:

```js
// config/mail.js
mailers: {
mailtrap: {
transport: 'mailtrap'
}
}
```

Also set the `default` option in `config/mails.js` to `mailtrap` or whatever name you call the mailer above.

```js
// config/mails.js
default: 'mailtrap'
```

## Mailtrap credentials

To set the Mailtrap credentials, you have a couple of options:

## Environment variables

Set the following environment variable:

```
MAILTRAP_TOKEN=f4k3t0k3n123
MAILTRAP_ACCOUNT_ID=2335532
MAILTRAP_TEST_INBOX_ID= 49469292 // Optional for email testing
```

## local.js

In development, you can specify a mailer of the same name in `local.js` so as to override the credentials like `apiKey` specified in `config/mail.js`

```js
// config/local.js
mail: {
mailers: {
mailtrap: {
token: 'f4k3t0k3n123',
accountId: 49495395,
testInboxId: 493923439 // Optional for email testing
}
}
}
```

## config/mail.js

You can set your credentials within the mailer defintion as well:

```js
// config/mail.js
mailers: {
mailtrap: {
transport: 'mailtrap',
token: process.env.MAILTRAP_TOKEN,
accountId: process.env.MAILTRAP_ACCOUNT_ID,
testInboxId: process.env.MAILTRAP_TEST_INBOX_ID // optional for email testing
}
}
```

Notice that for the `token`, `accountId`, and, `testInboxId`, in `config/mail.js` we are still using environment variables as its best practice not to add secrets to your codebase.

0 comments on commit 1be189c

Please sign in to comment.