npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-provider-email-extra

v0.3.0

Published

A wrapper email-provider for Strapi which supports localization email-templates and multiple email providers.

Downloads

84

Readme

Strapi Email Provider Extra

Overview

strapi-email-provider-extra is a email provider for the Strapi CMS that acts as a wrapper for various popular email providers such as MailGun, SendGrid, Mailjet, Azure Email, Resend, Nodemailer or etc. This plugin adds the functionality to send localized email templates based on the current or user-requested locale, enhancing the internationalization capabilities of your Strapi application.

Features

  • Flexible Provider Support: Easily integrate with your preferred email provider (Mailgun, SendGrid, Nodemailer, etc.).
  • Localization: Send emails using locale-specific templates to provide a personalized user experience.
  • Customizable: Configure and extend the plugin to suit your needs with ease.

Installation

  1. Install the Plugin:

    npm install strapi-email-provider-extra
  2. Configure the Plugin: Add the configuration to your config/plugins.js file:

    module.exports = ({ env }) => ({
      email: {
        config: {
    
          provider: 'strapi-provider-email-extra',
          providerOptions: {
            defaultProvider: 'nodemailer', // or 'mailgun', 'mailjet', etc.
            providers: {
              nodemailer: {
                provider: 'nodemailer',
                providerOptions: {
                  host: 'smtp.ethereal.email',
                  port: 587,
                  secure: false,
                  auth: {
                    user: '[email protected]',
                    pass: 'w6nhfjaAnKd7Asczzv',
                  }
                }
              }
            },
    
            // default template options
            dynamicTemplates: {
              enabled: true,
              collection: 'api::email-template.email-template',
              subjectMatcherField: 'subjectMatcher',
              testEmailMatcherSubject: 'Strapi test mail'
            }
          },
    
          // email settings
          settings: {
            defaultFrom: '[email protected]',
            defaultFromName: 'My Company'
          },
        }
      }
    })
  3. create a collection content in Content-Type Builder to localize your email template:

    Now, create a collection named EmailTemplate which api id: email-template. check internationalization checkbox in advance-setting tab when creating this collection. The EmailTemplate collection should contains this fields:

    • subjectMatcher as text
    • subject as text for your email subject
    • from as email (used in the from section of email)
    • text as rich-text for your email body
    • html as rich-text for your email body as html
  4. Add your email templates for "Account Confirmation" or "Reset-password" or any subject with your prefer locales :

    Now, add email templates with any locale you want to EmailTemplate with subjectMatcher for different categories:

    • subjectMatcher: 'Account Confirmation': for emails that the system will send when new user created to confirm account.
    • subjectMatcher: 'Reset Password': for emails that the system will send when user forget the password.
    • subjectMatcher: 'Strapi test mail':for test emails that you can send them through Strapi Admin UI.

Usage Examples

Now, when new user registered or forgot-password, the email content automatically fetched from your localized test templates with proper locale. the proper locale is chosen from default locale of strapi (can set in Strapi Admin UI), or from request's query option.

For example, to send a France email template in user registration api, call the register api like this with locale=fr in query params:

fetch('http://localhost:1337/api/auth/local/register?locale=fr', {
  method: 'POST',
  body: {
    username: 'my-user',
    email: '[email protected]',
    pass: '123456'
  }
})
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.error(error))

To send localized emails in your Strapi application, you can call the send method provided by the email's plugin.

const emailService = strapi.plugins.email.services.email

const emailOptions = {
  to: '[email protected]',
  subject: 'Welcome to Our Service', // the subject must exist in your test-template collection in `subjectMatcher` field.
  locale: 'fr', // Optional, defaults to configured default locale of strapi or will be fetched from user's request query.
}

await emailService.send(emailOptions)

Configuration Options

  • defaultProvider: The default email provider to use for sending email.
  • providers: Configuration for each supported email provider.
  • dynamicTemplates: Configuration for localized email templates.

Contributing

We welcome contributions to improve this project. To contribute, please fork the repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This project was inspired by the need for flexible and localized email sending capabilities within the Strapi CMS ecosystem.

With Strapi Email Provider Extra, you can now send personalized, localized emails with ease, leveraging your preferred email provider. Enjoy streamlined communication with your international user base!

For any issues or feature requests, please open an issue on our Issues.