This is a custom email provider for Strapi that enables sending emails using Novu as the email service.
Install the package via npm or yarn:
# npm
npm install strapi-provider-email-novu
# yarn
yarn add strapi-provider-email-novu
To configure the Novu email provider in your Strapi project, follow these steps:
- Install the
strapi-provider-email-novu
package:
# npm
npm install strapi-provider-email-novu
# yarn
yarn add strapi-provider-email-novu
-
In your Strapi project, create a new file called
config/plugins.js
(if it doesn't already exist). -
Add the following configuration to the
config/plugins.js
file:
module.exports = ({ env }) => ({
// Other plugins configuration
email: {
provider: 'strapi-provider-email-novu',
providerOptions: {
novuApiKey: env("NOVU_API_KEY"),
},
settings: {
defaultFrom: 'your-email@your-domain.com',
defaultReplyTo: 'your-email@your-domain.com',
},
},
});
Make sure to adjust process.env.NOVU_API_KEY
with your preferred method of retrieving the Novu API key.
The strapi-provider-email-novu
package provides the following methods:
Sends an email using Novu.
options
: An object containing the email parameters.to
: The recipient of the email. It can be an object withsubscriberId
,email
,firstName
, andlastName
properties, or an array of recipient objects.from
: The sender's email address.fromName
: The sender's name.subject
: The subject of the email.text
: The plain text version of the email.html
: The HTML version of the email.eventName
: The trigger identifier of the Novu workflow.payload
: Additional custom information to pass to the Novu workflow. please refer to https://docs.novu.co/platform/workflows for more information
Example usage:
await strapi.plugins['email'].services.email.send({
to: {
subscriberId: 'SUBSCRIBER_ID',
email: 'recipient@example.com',
firstName: 'John',
lastName: 'Doe',
},
from: 'sender@example.com',
fromName: 'Sender Name',
subject: 'Hello from Novu',
text: 'Plain text version of the email',
html: '<p>HTML version of the email</p>',
eventName: 'EVENT_NAME_FROM_ADMIN_PANEL',
payload: {
customVariables: 'VALUE_OR_OBJECT',
},
});
You can interact with the Novu API via custom methods provided by the Novu SDK. The following custom methods are available:
Adds a contact to a specific list.
await strapi.plugins.email.provider
.addContactToList({
id: 'email@example.com',
listId: 'mailingListId',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Creates a new contact with the specified email and name.
await strapi.plugins.email.provider
.createContact({
email: 'email@example.com',
name: 'John Doe',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Updates an existing contact with the specified data.
await strapi.plugins.email.provider
.updateContact('contactId', {
data: {
customField: 'customValue',
},
})
.catch((error) => console.log(error))
.then((response) => console.log
(response));
Creates a new contact list with the specified name.
await strapi.plugins.email.provider
.createContactList({
name: 'My Contact List',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Removes a contact from a specific list.
await strapi.plugins.email.provider
.removeContactFromList({
listId: 'mailingListId',
id: 'contactId',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Retrieves information about a specific contact.
await strapi.plugins.email.provider
.retrieveContact('contactId')
.catch((error) => console.log(error))
.then((response) => console.log(response));
Subscribes an existing contact to a specific list.
await strapi.plugins.email.provider
.subscribeContactToList({
listId: 'mailingListId',
id: 'contactId',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Unsubscribes a contact from a specific list.
await strapi.plugins.email.provider
.unsubscribeContactFromList({
listId: 'mailingListId',
id: 'contactId',
})
.catch((error) => console.log(error))
.then((response) => console.log(response));
Feel free to contribute to this repository by submitting a pull request.
This repository is MIT licensed.
Please note that the above README has been adapted from the strapi-provider-email-mailjet
README to fit the Novu email provider.
Authors: Scott Agirs
Initially published by sboutet06