Mandrill (deprecated, use mailchimp-transactional)

raw JSON →
1.0.60 verified Fri May 01 auth: no python deprecated

Mandrill is a Python client library for the Mandrill email as a service platform. As of version 1.0.60, the library is deprecated and replaced by mailchimp-transactional. No new releases are expected; users should migrate to the new library.

pip install mandrill
error ImportError: cannot import name 'Mandrill' from 'mandrill'
cause Using an older version of the library where the class was named MandrillAPI.
fix
Downgrade to version <1.0.50, or import as 'from mandrill import MandrillAPI'.
error mandrill.Error: Invalid API key
cause The provided API key is incorrect or not set.
fix
Ensure the MANDRILL_API_KEY environment variable is set to a valid Mandrill API key.
error ModuleNotFoundError: No module named 'distutils'
cause Python 3.12+ removed distutils, which the mandrill package depends on.
fix
Install setuptools: 'pip install setuptools' and retry. Or migrate to mailchimp-transactional.
error AttributeError: module 'mandrill' has no attribute 'MandrillAPI'
cause Using old import pattern with new library version (>=1.0.50).
fix
Change import to 'from mandrill import Mandrill'.
deprecated This library is deprecated in favor of mailchimp-transactional. New features and bug fixes are not being added.
fix Migrate to the mailchimp-transactional library: pip install mailchimp-transactional
breaking In version 1.0.50, the class name changed from MandrillAPI to Mandrill. Old import will break.
fix Use 'from mandrill import Mandrill' instead of 'from mandrill import MandrillAPI'.
gotcha The library does not support Python 3.12+ due to removed distutils dependency. Some users report install failures.
fix Install with 'pip install mandrill --use-deprecated=legacy-resolver' or use mailchimp-transactional.

Sends an email using the Mandrill API. Requires MANDRILL_API_KEY environment variable.

import mandrill

m = mandrill.Mandrill(api_key=os.environ.get('MANDRILL_API_KEY', ''))
try:
    result = m.messages.send(message={'subject': 'Hello', 'from_email': 'sender@example.com', 'to': [{'email': 'recipient@example.com'}]})
    print(result)
except mandrill.Error as e:
    print('Error:', e)