ijsto / strapi-provider-email-mailjet

Strapi Email service provider for Mailjet
MIT License
13 stars 11 forks source link

How use Mailjet template #6

Open TonyTR opened 3 years ago

TonyTR commented 3 years ago

hello @ScottAgirsit is possible to add the options of param the possibility of using a template ? (https://dev.mailjet.com/email/guides/template-api/) -> TemplateID: 1, with for example : settings: { defaultTemplateId: 1, }

ScottAgirs commented 3 years ago

Hey @TonyTR , thanks for opening this suggestion. Would you be interested in taking this on? If not then this could potentially be added early next year.

yosle commented 1 year ago

In case someone need this. You can acctually send templates , just need to add the corresponding parameters to the function like this. Note: text and html params must be sent because they are required by the function of you are gonna get errors, but they are ignored and the template is sent


// lifecycles.js

module.exports = {
  async afterCreate(event) {
    const { result } = event;
    try {
      await strapi.plugins["email"].services.email.send({
        to: result.email,
        from: "info@store.online", //e.g. single sender verification in SendGrid
        replyTo: "info@store.online",
        subject: "Welcome",
        text: "Bienvenido! " + result.name,
        html: "Bienvenido ! " + result.name,
        TemplateID: 4495580,
        TemplateLanguage: true,
        TemplateErrorDeliver: true,
        Variables: { name: result.name },
      });
    } catch (error) {
      console.log("Error sending welcome email ", error);
    }
  },
};```