Skip to content

Mailchimp Mandrill integration

Mailchimp Mandrill is a transactional email delivery service for websites and applications. Orvanta supports integration with Mailchimp Mandrill to trigger scripts and flows through parsed inbound emails via webhooks.

Integrating Mailchimp Mandrill is a powerful way of triggering scripts and flows by email.

Webhooks serve as a versatile method for triggering scripts or flows based on external events. Every script or flow automatically receives autogenerated webhooks accessible via the Details page.

These webhooks work with standard web technologies and are compatible with external systems like Mailchimp Mandrill. Bearer tokens must be passed as either an Authorization: Bearer <TOKEN> header or as a token query parameter.

  1. Create a script or flow with input designed to receive parsed results (e.g., a string called “mandrill_events”).
  2. Sign up to Mailchimp.
  3. Access the inbound menu in Mailchimp Mandrill.
  4. Add a domain or subdomain (e.g., webhooks.domain.com).
  5. Add MX records to your DNS provider and validate them.
  6. Create a new route specifying accepted email addresses.
  7. Obtain a webhook from your Orvanta script/flow Details page and create a token if needed.
  8. In Mandrill’s “Post to URL” field, paste the webhook: https://app.orvanta.cloud/.../rest_of_the_webhook/?token=TOKEN.
  9. Test DNS settings to verify functionality.

The email payload arrives as a string requiring JSON parsing. A simple parsing step can convert it:

export async function main(x) {
return JSON.parse(x);
}

Mailchimp parses email details and sends results as an array. Use the JSON parser step output to extract relevant information by “connecting inputs” from parsed details for subsequent workflow steps.

For forwarded emails, an additional parsing step is required since Mailchimp treats forwarded mail as a single email with the forwarder as the sender. Extract original sender details using regex patterns:

import re
def main(input_email):
from_pattern = re.compile(r'From: .+ <(.+)>')
subject_pattern = re.compile(r'Subject: (.+)')
date_pattern = re.compile(r'Date: (.+)')
to_pattern = re.compile(r'To: <(.+)>')
content_pattern = re.compile(r'\n\n(.*)\n', re.DOTALL)
from_field = re.search(from_pattern, input_email)
date_field = re.search(date_pattern, input_email)
subject_field = re.search(subject_pattern, input_email)
to_field = re.search(to_pattern, input_email)
content_field = re.search(content_pattern, input_email)
return {
'from': from_field.group(1) if from_field else None,
'date': date_field.group(1) if date_field else None,
'subject': subject_field.group(1) if subject_field else None,
'to': to_field.group(1) if to_field else None,
'content': content_field.group(1).strip() if content_field else None
}

To manage both directly routed and forwarded emails, implement conditional branching in your workflow. Use a script to detect forwarded emails (e.g., checking for “Fwd” in the subject):

export async function main(input: string, substring: string = 'Fwd'): Promise<Output> {
const containsSubstring = input.includes(substring);
return { containsSubstring };
}
interface Output {
containsSubstring: boolean;
}

Route execution based on the result using flow branches.

Potential applications include:

  • Conditional routing using branches based on email content
  • CRM integration (HubSpot, Airtable, Salesforce)
  • AI-powered email summarization
  • Automated invoice/receipt processing
  • System alerting and incident response automation
  • Task creation in project management tools