google-apps-scriptmailjet

Sending Mails using the Mailjet API with GAS


I would like to send mails via Google Apps Script using Mailjet. The problem is that there is no documentation at all on how to use this API with GAS.

Does any of you know some documentation somewhere about this use of Mailjet, or does any of you know a website to send mails like Sendgrid or Mailjet for which we can find documentation for the use of the API in GAS?

I tried the following code to send a basic email with JetMail but I can't make it work:

var mailjeturl = "https://api.mailjet.com/v3.1/send";

var mailjetparams = {
    "Messages":[{
      "From": {"Email": 'myemail@domain.com',"Name": 'Robert'},
      "To": [{"Email": 'theiremail@domain.com'}],
      "Subject": 'subject',
      "HTMLPart": 'this message',
}

var mailjetoptions = {
    'method': 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(mailjetparams)
};

var response = JSON.parse(UrlFetchApp.fetch(mailjeturl, mailjetoptions))

I actually don't know where to write my keys.

Thank you in advance for your answers,

Clank


Solution

  • If you're looking to interact with External API's using GAS, have a look at some of the documentation here:

    https://developers.google.com/apps-script/guides/services/external

    As for API interaction with MailJet, I would say look at the ES2015 Javascript wrapper as a starting point and see if it fits in with GAS. See here:

    https://github.com/mailjet/mailjet-apiv3-nodejs-es2015