Using sendinblue (or other email providers) with strapi

Hi,

I am trying to send transactional emails using strapi and sendinblue. What I want, for now:

  • when a visitor registers to our newsletter, he receives en email to confirm that he has registered.

Well, to be honest, I do not know where to start. I tried to install strapi-provider- email-sendinblue. And, then, what? :slight_smile:

Otherwise, my website is working, using quasar ssr and strapi…


Check out this step by step tutorial, using exactly Sendinblue

1 Like

Hi,
Thank you for your answer. I think the link will help me moving forward :slight_smile: .

Hi,

Looking at lifecycle hooks, I have found what I wanted. Here I can send a transactional email when a user register to the newsletter, using the sendinblue api (which makes more sense to me).
I share the code, if it might help someone else…

‘’'javascript
const validator = require(‘validator’);
const fetch = require(‘node-fetch’);

module.exports = {
lifecycles: {

async beforeCreate(data) {
  data.email = validator.normalizeEmail(data.email);
},

async afterCreate(result, data) {

  //step 1: add contact
  let url = 'https://api.sendinblue.com/v3/contacts';
  let options = {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
      'api-key': 'api key'
    },
    body: JSON.stringify({email: result.written_email})
  };

  let isAdded = null;
  try {
    const response = await fetch(url, options);
    isAdded = await response.json();
  } catch (error) {  
  }

  //step 2: send transactional email
  url = 'https://api.sendinblue.com/v3/smtp/email';
  options.body = JSON.stringify({to: [{email: result.written_email}], templateId: 2});

  let isSent = null;
  try {
    const response = await fetch(url, options);
    isSent = await response.json();
  } catch (error) { 
  }

}

},

};
‘’’

2 Likes

Before realizing that you found the solution for your problem, I was about to suggest to use mailgun - I used it a lot in many different contexts and was always very happy that I did

We had a lot of problems setting up Mailgun for a small application, it was even more problematic than SES. We are trying to make it work with SendGrid but as we have no a big company behind, it is hard to get an account there.