Skip to content

Sendinblue

Sendinblue is an all-in-one marketing platform with email marketing, transactional email, marketing automation, customer-relationship management, landing pages, Facebook ads, retargeting ads, SMS marketing, transactional SMS and more.

With Sendinblue, you can send 300 emails each day free of charge!

If you wish to send an email or SMS when a specific event in your mobile app or on your website occurs, you can write a KScript method to do this, that you can use as an action in an Automation.

This recipe assumes that you have KScripts enabled for your app and that you have your own Sendinblue account (with the Transactional SMS app in Sendinblue activated if required).

Email

Expand "Backend" in the left hand menu, select "API" and then click the "KScript" button. Create a new method called something like _mailer_ and include the following JavaScript function:

In this example, the full email content is sent in the API request. However, it is more likely that you will want to create templates (with parameters to be substituted at send time) in Sendinblue first, and include these in your API request along with the required parameters.

// {
//   "sender":{
//      "name":"Sender Alex",
//      "email":"[email protected]"
//   },
//   "to":[
//      {
//         "email":"[email protected]",
//         "name":"John Doe"
//      }
//   ],
//   "subject":"Hello world",
//   "htmlContent":"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>"
// }
function sendEmail(from, to, subject, content) {
    var client = K.http.createClient('https://api.sendinblue.com/');
    var API_KEY = 'YOUR_SENDINBLUE_APIKEY';

    var headers = {
        'api-key': API_KEY,
        'Content-Type': 'application/json'
    };

    var data =  {
        "sender": {
            "email": from
        },
        "to": [
            {
                "email": to
            }
        ],
        "subject": subject,
        "htmlContent": content
    };

    var result = client.post('/v3/smtp/email', K.JSON.stringify(data), headers);

    if (failed(result)) {
        K.log(result.error);
    }
    else if (result.isError()) {
        K.log(result.getBody());
    }

    return result;
}

You can then include your _mailer_ helper method and call the sendEmail() function from any scripts that need to send an email. To try it out, create another Kscript method called something like sendEmail, add input parameters(strings) for the from address, to address, subject and body and then paste in the following code:

include("_mailer_");

sendEmail(K.params.from, K.params.to, K.params.subject, K.params.body);

You can now test your new method and use as an action in an Automation.

If you are using our Backend feature, you can also call this method from your mobile app or, if you wish to send a recurring email (for example a digest of recent activity), this can be scheduled to run once per hour or day.

SMS

Expand "Backend" in the left hand menu, select "API" and then click the "KScript" button. Create a new method called something like _sms_ and include the following JavaScript function:

function sendSMS(from, to, text) {
    var client = K.http.createClient('https://api.sendinblue.com/');
    var API_KEY = 'YOUR_SENDINBLUE_APIKEY';

    var headers = {
        'api-key': API_KEY,
        'Content-Type': 'application/json'
    };


    var data =  {
        "sender" : from,
        "recipient" : to,
        "content" : text,
        "type": "transactional"
    };

    var result = client.post('/v3/transactionalSMS/sms', K.JSON.stringify(data), headers);

    if (failed(result)) {
        K.log(result.error);
    }
    else if (result.isError()) {
        K.log(result.getBody());
    }

    return result;
}

You can then include your _sms_ helper method and call the sendSMS() function from any scripts that need to send a sms. To try it out, create another Kscript method called something like sendSMS, add input parameters(strings) for the to number and text message and then paste in the following code:

include("_sms_");
var FROM = "Kumulos";

sendSMS(FROM, K.params.to, K.params.text);

You can now test your new method and use as an action in an Automation.

You will need to purchase SMS credits in your Sendinblue account to send SMS messages.

If you are using our Backend feature, you can also call this method from your mobile app or, if you wish to send a recurring SMS (for example a digest of recent activity), this can be scheduled to run once per hour or day.

Further reading

A full reference guide to the Sendinblue API service can be found on the Sendinblue website.