diff --git a/docs/.vitepress/config.mjs b/docs/.vitepress/config.mjs index 287a216..a72fd9d 100644 --- a/docs/.vitepress/config.mjs +++ b/docs/.vitepress/config.mjs @@ -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' } ] diff --git a/docs/mail/index.md b/docs/mail/index.md index 0968fd0..3d0cb2c 100644 --- a/docs/mail/index.md +++ b/docs/mail/index.md @@ -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. diff --git a/docs/mail/mailtrap-transport.md b/docs/mail/mailtrap-transport.md new file mode 100644 index 0000000..cebd772 --- /dev/null +++ b/docs/mail/mailtrap-transport.md @@ -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. diff --git a/package.json b/package.json index fab7c16..f9d017a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sailscasts-docs", - "version": "1.3.0", + "version": "1.4.0", "private": true, "description": "The official docs hub for Sailscasts", "scripts": {