Module mailchimp.transactional

ballerinax/mailchimp.transactional Ballerina library

1.0.0

Overview

Mailchimp Transactional Email is a reliable and scalable email delivery service provided by Intuit Mailchimp, designed for sending data-driven transactional emails such as password resets, order confirmations, and notifications.

The ballerinax/mailchimp.transactional package provides APIs to connect and interact with the Mailchimp Transactional API, enabling seamless integration with applications to manage transactional email sending, templates, messages, and more.

Setup guide

To use the Mailchimp Transactional Email connector, you need to have a Mailchimp account and access to a Mandrill API key. Follow the steps below to set up your account and generate the required API key.

Step 1: Create a Mailchimp account

  1. Go to the Mailchimp Sign Up Page and create a Mailchimp account.

  2. Once signed in, click on your profile icon in the top-right corner to access the account menu.

    Mailchimp Dashboard Mailchimp Profile Menu

Step 2: Enable transactional email

  1. In the menu, go to Billing.

    Mailchimp Billing Section

  2. Under Monthly plans or credits, select the Transactional Email Plan (you can start with the demo plan).

    Transactional Email Plan

Step 3: Generate a Mandrill API key

  1. After enabling the transactional email feature, navigate to the Extras section and click on API keys.

    Mailchimp Extra Section

  2. Choose Create A Mandrill API Key (not the regular API key). You will be redirected to the MandrillApp Dashboard.

    Mailchimp API Selection

  3. In the MandrillApp dashboard, click + Add API Key to generate your key.

    Mandrill API Key

  4. Copy the generated API key. You will need this to authenticate your connector.

    Create Mandrill API key

Quickstart

To use the Mailchimp Transactional connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the mailchimp.transactional module.

Copy
import ballerinax/mailchimp.'transactional as mailchimp;

Step 2: Configure the API key

  1. Create a Config.toml file and add your Mandrill API key obtained from the setup process:
Copy
key = "<Access Token>"
  1. Declare the key as a configurable variable and create a mailchimp.transactional:Client instance:
Copy
configurable string key = ?;
const string SERVER_URL = "server-url";

final mailchimp:Client mailchimp = check new ({}, SERVER_URL);

Step 3: Send a transactional email

Here’s how you can send a simple transactional email using the connector:

Copy
public function main() returns error? {
    mailchimp:MessagesSendBody payload = {
        key,
        message: {
            fromEmail: "noreply@yourdomain.com",
            to: [{ email: "customer@example.com"}],
            subject: "Your Order Confirmation",
            text: "Text",
            autoText: true
            
        }
    };
    mailchimp:InlineResponse20028[] sendResponse = check mailchimp->/messages/send.post(payload);
    if sendResponse.length() == 0 {
        io:println("No responses received.");
        return error("Empty response from Mailchimp API");
    }

    foreach var response in sendResponse {
        io:println("Email sent successfully: ", response.toBalString());
    }
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

The MailChimp Transactional Emails connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Transactional Template Flow: Shows how to create, publish, render, list, and delete templates.
  2. Webhook Lifecyle: Demonstrates creating, retrieving, updating, and deleting webhooks.

Import

import ballerinax/mailchimp.transactional;Copy

Other versions

1.0.0

Metadata

Released date: 20 days ago

Version: 1.0.0

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 1

Current verison: 1


Weekly downloads


Source repository


Keywords

mailchimp

transactional

email

email-connector

ballerina

ballerina-connector

campaigns


Contributors