90 lines
2.1 KiB
Markdown
Raw Normal View History

# Email
2019-09-24 13:46:33 +02:00
::: note
This feature requires the Email plugin (installed by default).
:::
Thanks to the plugin `Email`, you can send email on your server or externals providers such as Sendgrid.
2019-09-24 13:46:33 +02:00
## Programmatic usage
```js
await strapi.plugins['email'].services.email.send({
2019-09-24 13:46:33 +02:00
to: 'paulbocuse@strapi.io',
from: 'joelrobuchon@strapi.io',
replyTo: 'no-reply@strapi.io',
subject: 'Use strapi email provider successfully',
text: 'Hello world!',
2019-07-18 19:28:52 +02:00
html: 'Hello world!',
});
```
2019-09-24 13:46:33 +02:00
## Install new providers
By default Strapi provides a local email system. You might want to send email with a third party.
You can check all the available providers developed by the community on npmjs.org - [Providers list](https://www.npmjs.com/search?q=strapi-provider-email-)
To install a new provider run:
2019-09-24 13:46:33 +02:00
:::: tabs cache-lifetime="10" :options="{ useUrlFragment: false }"
::: tab "yarn"
```
yarn add strapi-provider-email-sendgrid@beta --save
```
:::
::: tab "npm"
```
2019-09-24 13:46:33 +02:00
npm install strapi-provider-email-sendgrid@beta --save
```
2019-09-24 13:46:33 +02:00
:::
::::
::: note
2019-05-16 09:56:33 +02:00
If the provider is not in the mono repo, you probably don't need `@beta` depending if the creator published it with this tag or not.
:::
2019-09-24 13:46:33 +02:00
## Configure the plugin
The plugin provide you a setting page to be able to define the email provider you want to use.
You will also be able to add some configuration.
2019-09-24 13:46:33 +02:00
- Click on **Plugins** in the left menu
- Click on the cog button on the **Email** plugin line
## Create new provider
2019-07-05 03:05:36 +02:00
If you want to create your own, make sure the name starts with `strapi-provider-email-` (duplicating an existing one will be easier), modify the `auth` config object and customize the `send` function.
2019-09-24 13:46:33 +02:00
Default template
```js
module.exports = {
provider: 'provider-id',
name: 'display name',
auth: {
config_1: {
label: 'My Config 1',
type: 'text',
},
},
init: config => {
return {
send: async options => {},
};
},
};
```
In the `send` function you will have access to:
- `config` that contain configuration you setup in your admin panel
- `options` that contain option your send when you called the `send` function from the email plugin service