1.1.0 • Published 3 years ago

@yanotoma/strapi-provider-email-sendinblue v1.1.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

strapi-provider-email-sendinblue

Resources

Links

Prerequisites

You need to have the plugin strapi-plugin-email installed in you Strapi project.

Installation

# using yarn
yarn add @yanotoma/strapi-provider-email-sendinblue

# using npm
npm install @yanotoma/strapi-provider-email-sendinblue --save

Configuration

package.json

Since the name of the package has an scope you have to add an alias.

replace <version> with the version you have installed. ex. npm:@yanotoma/strapi-provider-email-sendinblue@1.0.1

  "dependencies": {
    ...
    "strapi-provider-email-sendinblue": "npm:@yanotoma/strapi-provider-email-sendinblue@<version>"
    ...
  }

Config params

VariableTypeDescriptionRequiredDefault
providerstringThe name of the provider you useyes
providerOptionsobjectProvider optionsyes
providerOptions.apiKeyobjectApi key given to the function setApiKeyyes
settingsobjectSettingsno{}
settings.defaultFromstringDefault sender mail addressnoundefined
settings.defaultFromNamestringDefault name of the sendernoundefined
settings.defaultReplyTostringDefault address the receiver is asked to reply tonoundefined

Example

Path - config/plugins.js

module.exports = ({ env }) => ({
  // ...
  email: {
    provider: "sendinblue",
    providerOptions: {
      apiKey: env("SENDINBLUE_API_KEY"),
    },
    settings: {
      defaultFrom: "myemail@mail.com",
      defaultFromName: "My name",
      defaultReplyTo: "myemail@mail.com",
    },
  },
  // ...
});

Usage

Params

VariableTypeDescriptionRequired
tostringaddress of the receiveryes
fromstringaddress of the senderno
fromNamestringanme of the senderno
replyTostringaddress the receiver is asked to reply tono
subjectstringsubject of the emailyes
htmlstringhtml email bodyif there is not templateId
textstringtext email bodyif there is not templateId
templateIdnumberid of the template created in Sendinblueif there is not html
paramsobjectparams to tjat will override the templateno
tagsstring[]array of string to add to the transactional email recordno
contactobjectdata to add or update a contactno
contact.emailstringaddress to add to the contacts listyes
contact.attributesobjectattributes to add with the email addressno

Examples

// using html and text
const user = {
  name: 'Jhon Doe',
  email: 'jd@mail.com',
};

const html = `<h1>Hello ${user.name}</h1>`;
const text = `Hello ${user.name}`

await strapi.plugins.email.services.email.send({
  to: user.email,
  subject: 'This is a test!'
  html,
  text,
  tags: ['test', 'hello']
});
// using template id
const user = {
  name: 'Jhon Doe',
  email: 'jd@mail.com',
};


await strapi.plugins.email.services.email.send({
  to: user.email,
  subject: 'This is a test!'
  templateId: 1,
  params: user,
  tags: ['test', 'hello', 'template']
});
// adding a contact

// attributes may change depending on your configuration and language
const contact = {
  email: 'jd@mail.com',
  attributes: {
    'FIRSTNAME': 'Jhon',
    'LASTNAME': 'Doe'
  }
};

const html = `<h1>Hello ${user.attributes.FIRSTNAME}</h1>`;
const text = `Hello ${user.attributes.FIRSTNAME}`

await strapi.plugins.email.services.email.send({
  to: user.email,
  subject: 'This is a test!'
  html,
  text,
  tags: ['test', 'hello'],
  contact
});