The Mailchimp/Mandrill Notification Service is a microservice responsible for interacting with Mailchimp and Mandrill for:
- Sending transactional emails: using Mailchimp defined email templates and Mandrill transactional APIs
- Interact with Mailchimp audiences: subscription, deletion, user status update
1) Sending transactional emails
Transactional email service is provided with 2 main endpoints:
-
Synchronous: waits for Mailchimp/Mandrill to have actually queued the transactional email request
-
Asynchronous: fire and forget. The endpoint immediately returns, and the request is sent to Mailchimp/Mandrill but the service will not wait for Mailchimp/Mandrill response
Synchronous transactional email send
The service is provided through the POST /transactional/send-template endpoint.
An example JSON body is presented below:
{
"templateName": "my_template",
"subject": "Hello world!",
"fromEmail": "example@test.com",
"fromName": "Visible subject name",
"templateMergeVars": [
{
"name": "HELLO_WORLD",
"content": "I can provide the content I want here"
},
],
"to": [
{
"email": "receiver@test.com",
"type": "to"
},
{
"email": "cc@test.com",
"type": "cc"
},
{
"email": "bcc@test.com",
"type": "bcc"
}
],
"attachments": [
{
"mimeType": "application/pdf",
"visibleName": "example.pdf",
"base64Content": "base64encodedContent",
}
]
}
templateName: name of the email template as created in MailchimpContent -> Email Templatessection.- NB: a
Send To Mandrillaction on the template from the Mailchimp UI is required to be able to send transactional emails using the template defined
- NB: a
subject: Email subjectfromEmail: this is the email sender addressfromName: this is the email friendly sender nametemplateMergeVars: array body parameter- each array entry defines an email
MERGE TAG: in case the transactional email requires custom parameters inside its body, those can be provided using thetemplateMergeVarsarray - each entry contains:
name: name of the merge tag on the Mailchimp email template. Here is an example email template on Mailchimp, with aHELLO_WORLDmerge tag:
My beautiful email has a merge tag *|HELLO_WORLD|*.
Merge tags inside the Mailchimp email template must be within *| and |*.
HELLO_WORLD can be filled with the string content I need.content: string content to be placed inside the merge tag specified by the parametername
- each array entry defines an email
to: array body parameter- multiple
toarray items can be specified type: can be one amongto|cc|bccemail: email for which thetypeparameter applies
- multiple
attachments:- is an array to push attachments to the email to be sent
- every array item must have the following fields:
mimeType: attachment MIME TypevisibleName: attachment name which will be visible in the email templatebase64Content: attachment Base 64 content
Here an example response for the endpoint POST /transactional/send-template:
{
"_id": "df4caa05c99746b8863e08cc039b17c5"
}
Parameter _id is the internal Mandrill id for the transactional email just sent.
Asynchronous transactional email send
In case a fire and forget transactional Mandrill email send is needed, the endpoint POST /transactional/send-template-async is provided.
The JSON input body is the same as the one used for the POST /transactional/send-template endpoint.
Here is an example response for the endpoint POST /transactional/send-template-async:
{
"_id": "queued"
}
Parameter _id is always queued since we do not wait for Mandrill to get the transactional status of the email sent.
2) Mailchimp audiences (newsletters) management
Audience (newsletter) service is provided with 2 main endpoints:
-
POST /marketing/audiences/membership: determines whether a user, specified by its email, belongs to a specific newsletter list (audience) -
PUT /marketing/audiences/update-subscription: update the subscription of a user (email) to an audience (newsletter list)
POST /marketing/audiences/membership
An example input JSON body is presented below:
{
"email": "mytestemail@test.com",
"listId": "c3baaef21456"
}
The endpoint takes in input a JSON body as follows:
-
email: The email of the user for which membership to the audience (specified bylistId) needs to be checked -
listId: newsletter list id. Can be found directly on Mailchimp after the audience creation or in the audience details (if the audience already exists)
An example response JSON body is presented below:
{
"membership": true,
"status": "pending"
}
The endpoint response body is as follows:
-
membership: can betrue|false,trueif the user is within the audience -
status: only present ifmembershipis valued astrue. Determines the status of the email in the audience list, using Mandrill newsletter statuses.
PUT /marketing/audiences/update-subscription
An example input JSON body is presented below:
{
"listId": "c3baaef2e2",
"status": "subscribed",
"email": "testemail@test.com"
}
listId: newsletter list id. Can be found directly on Mailchimp after the audience creation or in the audience details (if audience already exists)status: desired final status for the email in the newsletter specified bylistId.- e.g.
subscribedif we want to subscribe the email to the list. - e.g.
unsubscribedif we want to unsubscribe the email from the list
- e.g.
email: email for which we want to update subscription status to the newsletter specified bylistId
An example response JSON body is presented below:
{
"status": "subscribed"
}
in this case, the email has been subscribed to the newsletter.
status: new status for theemailinside the audience specified bylistId