Strapi Microsoft Graph Email Provider
Strapi custom email provider for Microsoft Graph
Strapi Microsoft Graph Email Provider
This project provides a custom email provider for Strapi using Microsoft Graph API. It allows sending emails through Microsoft Graph, leveraging the powerful features and integration capabilities of Azure services.
Features
- Send emails using Microsoft Graph API
- Support for custom
from,replyTo, andapiSenderaddresses - Support for HTML and text email bodies
- Ability to add attachments
- Easy configuration and initialization
Installation
To install the Microsoft Graph Email Provider, run the following command:
npm install strapi-provider-email-microsoft-graphConfiguration
You need to configure the provider with your Microsoft Graph API credentials. Add the following configuration to your Strapi project.
Provider Options
| Option | Type | Description |
|---|---|---|
tenantId | string | Your Azure AD tenant ID |
clientId | string | Your application client ID |
clientSecret | string | Your application client secret |
Settings
| Option | Type | Description |
|---|---|---|
defaultFrom | string | Default from email address |
defaultReplyTo | string | Default replyTo email address |
defaultApiSender | string | Default API sender email address |
Example Configuration
1// config/plugins.js
2
3module.exports = ({ env }) => ({
4 email: {
5 config: {
6 provider: "strapi-provider-email-microsoft-graph",
7 providerOptions: {
8 tenantId: env("MICROSOFT_GRAPH_TENANT_ID"),
9 clientId: env("MICROSOFT_GRAPH_CLIENT_ID"),
10 clientSecret: env("MICROSOFT_GRAPH_CLIENT_SECRET"),
11 },
12 settings: {
13 defaultFrom: "no-reply@example.com",
14 defaultReplyTo: "support@example.com",
15 defaultApiSender: "api@example.com",
16 },
17 },
18 },
19});Usage
Sending an Email
To send an email, use the send function provided by the email provider. Here is an example:
1// controllers/email.js
2
3module.exports = {
4 async sendEmail(ctx) {
5 const { to, subject, text, html, attachments } = ctx.request.body;
6
7 try {
8 await strapi.plugins["email"].services.email.send({
9 to,
10 subject,
11 text,
12 html,
13 attachments,
14 });
15 ctx.send({ message: "Email sent successfully" });
16 } catch (err) {
17 ctx.send({ error: "Failed to send email" });
18 }
19 },
20};Send Options
| Option | Type | Description |
|---|---|---|
to | string | Recipient email address |
subject | string | Subject of the email |
from | string (optional if defaultFrom is defined in provider settings) | Email address of the sender |
apiSender | string (optional if defaultApiSender is defined in provider settings) | API sender email address |
cc | string (optional) | CC email addresses, comma-separated |
bcc | string (optional) | BCC email addresses, comma-separated |
replyTo | string (optional) | Reply-to email address |
text | string (optional) | Text body of the email |
html | string (optional) | HTML body of the email |
attachments | array (optional) | Attachments to include in the email |
Contributing
Contributions are welcome! If you have any improvements or suggestions, feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Install now
npm install strapi-provider-email-microsoft-graph
Create your own plugin
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.