Wolkendama-API / utils / sendinblue.js
sendinblue.js
Raw
const sendInBlue = require("sib-api-v3-sdk");
sendInBlue.ApiClient.instance.authentications["api-key"].apiKey =
  process.env.SENDINBLUE_API;

exports.sendPurchaseConfirmationEmail = (
  toCustomerName,
  toCustomerEmail,
  params
) => {
  new sendInBlue.TransactionalEmailsApi()
    .sendTransacEmail({
      templateId: 1,
      replyTo: { email: "conan@wolkendama.com", name: "Conan" },
      to: [{ name: toCustomerName, email: toCustomerEmail }],
      params,
    })
    .then(
      function (data) {
        console.log(
          `${new Date()} Purchase confirmation email has benn sent to ${toCustomerEmail}, with message Id: ${
            data.messageId
          }`
        );
      },
      function (error) {
        console.error(error);
      }
    );
};

exports.sendTrackingNoEmail = (toCustomerName, toCustomerEmail, params) => {
  new sendInBlue.TransactionalEmailsApi()
    .sendTransacEmail({
      templateId: 2,
      replyTo: { email: "conan@wolkendama.com", name: "Conan" },
      to: [{ name: toCustomerName, email: toCustomerEmail }],
      params,
    })
    .then(
      function (data) {
        console.log(
          `${new Date()} Tracking no email has been sent to ${toCustomerEmail}, with message Id: ${
            data.messageId
          }`
        );
      },
      function (error) {
        console.error(error);
      }
    );
};