-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
210 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ next: | |
|
||
To configure mail, create a `config/mail.js` configuration file. Let's look at all the possible configurations you can have in `config/mail.js` | ||
|
||
## default | ||
## `default` | ||
|
||
The `default` config in `config/mail.js` tells Mail which mailer to use by default. The string passed to `default` must be the name of a registered mailer in the `mailers` object | ||
|
||
|
@@ -40,7 +40,7 @@ mail: { | |
} | ||
``` | ||
|
||
## mailers | ||
## `mailers` | ||
|
||
The `mailers` configuration object contains | ||
|
||
|
@@ -63,9 +63,9 @@ The `mailers` configuration object contains | |
In Mail, a mailer is a configuration object that is registered in the `mailers` object in `config/mails.js` or in a `mail` object in `local.js` that specifies at the very least a transport that Mail will use in sending your emails. | ||
::: | ||
|
||
## from | ||
## `from` | ||
|
||
This config let you set a global from address for all your emails. It's really useful if your application sends emails from the same from address. | ||
This config lets you set a global from address for all your emails. It's really useful if your application sends emails from the same from address. | ||
|
||
By default Mail will use this address if no address is passed when you send an email with `sails.helpers.mail.send` | ||
|
||
|
@@ -77,3 +77,15 @@ from: { | |
``` | ||
|
||
You can also set this config by specifying these two environment variables: `MAIL_FROM_NAME` and `MAIL_FROM_ADDRESS`. | ||
|
||
## `replyTo` | ||
|
||
This config lets you set a global reply-to address for all your emails. It's useful if you want replies to go to a specific address. | ||
|
||
Mail will use this address by default if no `replyTo` address is provided when sending an email with `sails.helpers.mail.send`. | ||
|
||
```js | ||
replyTo: '[email protected]' | ||
``` | ||
|
||
You can also set this config by specifying the environment variable `MAIL_REPLY_TO`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ next: false | |
|
||
Mail provides a `send` helper that is used to send your emails within your Sails applications. The `send` helper takes in several optional and required arguments like `mailer`, `template`, `templateData` etc. | ||
|
||
## mailer | ||
## `mailer` | ||
|
||
The mailer to use for sending the email. This is optional because by default Mail will look for the mailer to use by checking for it in the following places: | ||
|
||
|
@@ -27,63 +27,79 @@ The mailer to use for sending the email. This is optional because by default Mai | |
sails.helpers.mail.send.with({ mailer: 'resend' }) | ||
``` | ||
|
||
## template <Badge type="danger">required</Badge> | ||
## `template` | ||
|
||
This is a string matching an [email template](/mail/email-template) in `views/emails` without the file extension. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ template: 'email-verify-account' }) | ||
``` | ||
|
||
## templateData | ||
## `templateData` | ||
|
||
A dictionary of data which will be accessible in your email template. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ templateData: { fullName: 'Jack Sparrow' } }) | ||
``` | ||
|
||
## to <Badge type="danger">required</Badge> | ||
## `to` <Badge type="danger">required</Badge> | ||
|
||
The email address of the primary recipient. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ to: '[email protected]' }) | ||
``` | ||
|
||
## toName | ||
## `toName` | ||
|
||
The name of the primary recipient | ||
|
||
```js | ||
sails.helpers.mail.send.with({ toName: 'Jack Sparrow' }) | ||
``` | ||
|
||
## subject | ||
## `cc` <Badge>SMTP</Badge> <Badge>Resend</Badge> | ||
|
||
The email addresses to send a carbon copy of the mail to. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ cc: ['[email protected]'] }) | ||
``` | ||
|
||
## `bcc` <Badge>SMTP</Badge> <Badge>Resend</Badge> | ||
|
||
The email addresses to send a blind carbon copy of the mail to. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ cc: ['[email protected]'] }) | ||
``` | ||
|
||
## `subject` | ||
|
||
The subject of the email. | ||
|
||
```js | ||
sails.helpers.mail.send.with({ subject: 'Verify email' }) | ||
``` | ||
|
||
## from | ||
## `from` | ||
|
||
The from email to use to send the email. This isn't required because you can specify a [global from](/mail/configuration#from) | ||
|
||
```js | ||
sails.helpers.mail.send.with({ from: '[email protected]' }) | ||
``` | ||
|
||
## fromName | ||
## `fromName` | ||
|
||
The from name to use to send the email. This isn't required because you can specify a [global from](/mail/configuration#from) | ||
|
||
```js | ||
sails.helpers.mail.send.with({ fromName: 'The Boring JavaScript Stack' }) | ||
``` | ||
|
||
## layout | ||
## `layout` | ||
|
||
The email layout to use for this email. This isn't required because by default Mail will look for a layout called `layout-email`. | ||
|
||
|
@@ -92,7 +108,7 @@ However with `layout` you can pass an override and chose another layout to use o | |
### Specify a layout | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ layout: 'layout-accout' }) | ||
await sails.helpers.mail.send.with({ layout: 'layout-account' }) | ||
``` | ||
|
||
### Disable layout | ||
|
@@ -101,14 +117,177 @@ await sails.helpers.mail.send.with({ layout: 'layout-accout' }) | |
await sails.helpers.mail.send.with({ layout: false }) | ||
``` | ||
|
||
## text | ||
## `text` | ||
|
||
Specify email plain text. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ text: 'Verify your email' }) | ||
``` | ||
|
||
## `attachments` | ||
|
||
An optional array of attachment objects. Each attachment object should have the following properties: | ||
|
||
- `filename`: The name of the file. | ||
- `path`: The path to the file. | ||
- `contentType`: The MIME type of the file (optional). | ||
- `content`: String, Buffer or a Stream contents for the attachment (optional). | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
to: '[email protected]', | ||
toName: 'Jack Sparrow', | ||
template: 'email-verify-account', | ||
templateData: { token: '3828bsbababvbas', fullName: 'Jack Sparrow' }, | ||
attachments: [ | ||
{ | ||
filename: 'adventure-log.txt', | ||
content: 'The journey begins...' | ||
}, | ||
{ | ||
filename: 'treasure-map.txt', | ||
content: new Buffer('X marks the spot!', 'utf-8') | ||
}, | ||
{ | ||
filename: 'crew-list.txt', | ||
path: '/path/to/crew-list.txt' | ||
}, | ||
{ | ||
filename: 'ship-photo.jpg', | ||
path: '/path/to/ship-photo.jpg', | ||
contentType: 'image/jpeg' | ||
} | ||
] | ||
}) | ||
``` | ||
|
||
## `replyTo` <Badge>SMTP</Badge> <Badge>Resend</Badge> | ||
|
||
An email address that will appear on the Reply-To: field. This isn't required because you can specify a [global replyTo](/mail/configuration#replyTo). | ||
|
||
```js | ||
sails.helpers.mail.send.with({ replyTo: '[email protected]' }) | ||
``` | ||
|
||
## `category` <Badge>Mailtrap</Badge> | ||
|
||
The category of the email. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
category: 'verify' | ||
}) | ||
``` | ||
|
||
## `customVariables` <Badge>Mailtrap</Badge> | ||
|
||
An object with custom variables to use in the email. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
customVariables: { | ||
shipName: 'Black Pearl', | ||
captain: 'Jack Sparrow' | ||
} | ||
}) | ||
``` | ||
|
||
## `templateUuid` <Badge>Mailtrap</Badge> | ||
|
||
The UUID of the template to use. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
templateUuid: '123e4567-e89b-12d3-a456-426614174000' | ||
}) | ||
``` | ||
|
||
## `templateVariables` <Badge>Mailtrap</Badge> | ||
|
||
An object with the variables to use in the template. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
templateUuid: '123e4567-e89b-12d3-a456-426614174000', | ||
templateVariables: { | ||
shipName: 'Black Pearl', | ||
captain: 'Jack Sparrow' | ||
} | ||
}) | ||
``` | ||
|
||
## `testInboxId` <Badge>Mailtrap</Badge> | ||
|
||
The ID of the test inbox to use. | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
to: '[email protected]', | ||
toName: 'Jack Sparrow', | ||
template: 'email-verify-account', | ||
templateData: { token: '3828bsbababvbas', fullName: 'Jack Sparrow' }, | ||
testInboxId: 5353939 | ||
}) | ||
``` | ||
|
||
## `react` <Badge>Resend</Badge> | ||
|
||
If you are using [React Email](https://react.email/), you can pass the the React component you used in writing the message to `react`. | ||
|
||
:::code-group | ||
|
||
```jsx[important-message.jsx] | ||
import * as React from 'react' | ||
import { Html, Button, Container, Heading, Text } from '@react-email/components' | ||
export default function Email(props) { | ||
const { url, recipientName } = props | ||
return ( | ||
<Html lang="en"> | ||
<Container> | ||
<Heading>Ahoy, {recipientName}!</Heading> | ||
<Text>We have an important message for you. Click the button below to read it:</Text> | ||
<Button href={url}>Read Message</Button> | ||
<Text>Fair winds and following seas,</Text> | ||
<Text>The Black Pearl Crew</Text> | ||
</Container> | ||
</Html> | ||
) | ||
} | ||
``` | ||
|
||
```js [signup.js] | ||
const Email = require('../../assets/emails/important-message') | ||
|
||
await sails.helpers.mail.send.with({ | ||
react: <Email url="https://example.com" recipientName="Jack Sparrow" />, | ||
to: '[email protected]', | ||
toName: 'Jack Sparrow' | ||
}) | ||
``` | ||
|
||
::: | ||
|
||
:::tip | ||
Make sure you have `@react-email/components` installed to use React components as email | ||
::: | ||
|
||
## `scheduledAt` <Badge>Resend</Badge> | ||
|
||
Schedule email to be sent later. The date should be in natural language (e.g.: in 1 min) or ISO 8601 format (e.g: 2024-08-05T11:52:01.858Z). | ||
|
||
```js | ||
await sails.helpers.mail.send.with({ | ||
to: '[email protected]', | ||
toName: 'Jack Sparrow', | ||
template: 'email-verify-account', | ||
templateData: { token: '3828bsbababvbas', fullName: 'Jack Sparrow' }, | ||
scheduledAt: '2024-08-05T11:52:01.858Z' | ||
}) | ||
``` | ||
|
||
## Examples | ||
|
||
### Send email with template | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters