Email Newsletter Integration in Outerbase

Email Newsletter Integration in Outerbase

This article is about the development of the Send Email Outerbase command as part of the Outerbase & Hashnode hackathon

ยท

3 min read

Introduction

Outerbase Commands offer a flexible method for simplifying a variety of tasks within the Outerbase ecosystem. It will integrate any popular APIs to view the details of the desired functionality effortlessly. For more information about Outerbase commands, please refer to the official documentation here

This article discusses about the development of Outerbase command for SendinBlue email integration.

SendinBlue

SendinBlue is a comprehensive marketing automation platform and email marketing service that helps businesses and organizations engage with their audiences more effectively. It offers a suite of tools for email marketing, SMS campaigns, marketing automation, transactional emails, and more.

With user-friendly features and automation capabilities, SendinBlue is popular among businesses of all sizes for managing and optimizing their marketing campaigns, improving customer engagement, and driving growth

SendinBlue Email API

Below is the sample curl request to use SendinBlue Email API

curl --request POST \
  --url https://api.brevo.com/v3/smtp/email \
  --header 'accept: application/json' \
  --header 'api-key:YOUR_API_KEY' \
  --header 'content-type: application/json' \
  --data '{  
   "sender":{  
      "name":"Sender Alex",
      "email":"senderalex@example.com"
   },
   "to":[  
      {  
         "email":"testmail@example.com",
         "name":"John Doe"
      }
   ],
   "subject":"Hello world",
   "htmlContent":"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Brevo.</p></body></html>"
}'

For more information, please refer to the documentation link attached here

Testing SendinBlue Email API

After following the documentation, it is time to test whether the API works. Below is a quick python snippet that will help to do just that

import requests

url = "https://api.brevo.com/v3/smtp/email"

headers = {
    "accept": "application/json",
    "api-key": "YOUR_API_KEY",
    "content-type": "application/json"
}

data = {
    "sender": {
        "name": "user2",
        "email": "email2@gmail.com"
    },
    "to": [
        {
            "email": "email1@gmail.com",
            "name": "user1"
        }
    ],
    "subject": "Hello world",
    "htmlContent": "<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Brevo.</p></body></html>"
}

response = requests.post(url, headers=headers, json=data)

if response.status_code == 201:
    print("Email sent successfully.")
else:
    print(f"Email sending failed with status code: {response.status_code}")
    print(response.text)

Outerbase Command

After testing the API, it is time to write your Outerbase Command function.

async function userCode() {

    const email = {{request.body.email}}
    const fname = {{request.body.name}}

    if (!email) {
        return {
            status: 400,
            error: "missing email from request body"
        }
    }

    if (!fname) {
        return {
            status: 400,
            error: "missing name from request body"
        }
    }

    const headers = {
        "accept": "application/json",
        "api-key": "<your-api-key>",
        "content-type": "application/json"
    };

    const data = JSON.stringify({
        "sender": {
            "name": "Balaji Seetharaman",
            "email": "balaji281295@gmail.com"
        },
        "to": [
            {
                "email": email,
                "name": fname
            }
        ],
        "subject": "Hello world",
        "htmlContent": "<html><head></head><body><p>Hello,</p>Thanks for signing up to this newsletter.</p></body></html>"
    });

    const response = await fetch("https://api.brevo.com/v3/smtp/email", {
        method: "POST",
        headers: headers,
        body: data
    })

return response.json()

}

Newsletter Signup streamlit app

For the quick POC, I have developed a Streamlit App that does the newsletter signup functionality. Below are the screenshots that explain about the App and its functionality

https://emailnewsletter-command-outerbase.streamlit.app/

Please find the attached link to the demo video here & Github Repository link here

Conclusion

Integration of SendinBlue as Outerbase command will help you to send targeted campaign emails seamlessly to the audience of your interest. Please let me know if you have any questions.

A big thank you for taking the time to read my article and shoutout to the outerbase & hashnode team for hosting this amazing hackathon. Please support me by liking the article and sharing the article if you like it, and follow me for more related articles.

#outerbase #outerbasehackathon #hashnode

Did you find this article valuable?

Support Balaji Seetharaman by becoming a sponsor. Any amount is appreciated!

ย