1.0.0 • Published 8 months ago

strapi-provider-email-microsoft-graph-custom v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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, and apiSender addresses
  • 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-graph

Configuration

You need to configure the provider with your Microsoft Graph API credentials. Add the following configuration to your Strapi project.

Provider Options

OptionTypeDescription
tenantIdstringYour Azure AD tenant ID
clientIdstringYour application client ID
clientSecretstringYour application client secret

Settings

OptionTypeDescription
defaultFromstringDefault from email address
defaultReplyTostringDefault replyTo email address
defaultApiSenderstringDefault API sender email address

Example Configuration

// config/plugins.js

module.exports = ({ env }) => ({
  email: {
    config: {
      provider: "strapi-provider-email-microsoft-graph",
      providerOptions: {
        tenantId: env("MICROSOFT_GRAPH_TENANT_ID"),
        clientId: env("MICROSOFT_GRAPH_CLIENT_ID"),
        clientSecret: env("MICROSOFT_GRAPH_CLIENT_SECRET"),
      },
      settings: {
        defaultFrom: "no-reply@example.com",
        defaultReplyTo: "support@example.com",
        defaultApiSender: "api@example.com",
      },
    },
  },
});

Usage

Sending an Email

To send an email, use the send function provided by the email provider. Here is an example:

// controllers/email.js

module.exports = {
  async sendEmail(ctx) {
    const { to, subject, text, html, attachments } = ctx.request.body;

    try {
      await strapi.plugins["email"].services.email.send({
        to,
        subject,
        text,
        html,
        attachments,
      });
      ctx.send({ message: "Email sent successfully" });
    } catch (err) {
      ctx.send({ error: "Failed to send email" });
    }
  },
};

Send Options

OptionTypeDescription
tostringRecipient email address
subjectstringSubject of the email
fromstring (optional if defaultFrom is defined in provider settings)Email address of the sender
apiSenderstring (optional if defaultApiSender is defined in provider settings)API sender email address
ccstring (optional)CC email addresses, comma-separated
bccstring (optional)BCC email addresses, comma-separated
replyTostring (optional)Reply-to email address
textstring (optional)Text body of the email
htmlstring (optional)HTML body of the email
attachmentsarray (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.