Registry / communication / mailjet-rest

mailjet-rest

JSON →
library1.8.0pypypi✓ verified 22d ago

mailjet-rest is the official Python wrapper for the Mailjet Email API (v3 and v3.1). It simplifies sending transactional and marketing emails, managing contacts, and retrieving statistics. The library is currently at version 1.5.1 and receives regular updates and maintenance.

pip install mailjet-rest
INSTALL
IMPORT
SIG · MAILJET-REST
M
mailjet-rest
communicationpythonv1.8.0
Install
2.1s avg
Import
430ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.440s · 21.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.420s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from mailjet_rest import Client

This quickstart demonstrates how to initialize the Mailjet client and send a basic email. Ensure your Mailjet API public and private keys are set as environment variables (MJ_APIKEY_PUBLIC, MJ_APIKEY_PRIVATE) or replaced with actual keys. The 'From' email address must be a verified sender in your Mailjet account. The example uses the v3.1 Send API for more robust messaging features.

import os from mailjet_rest import Client # Mailjet API keys can be found at https://app.mailjet.com/account/api_keys # It's highly recommended to store these in environment variables. api_key = os.environ.get('MJ_APIKEY_PUBLIC', 'your_public_api_key_here') api_secret = os.environ.get('MJ_APIKEY_PRIVATE', 'your_private_api_secret_here') # Initialize the Mailjet client, specifying API version v3.1 for the Send API. mailjet = Client(auth=(api_key, api_secret), version='v3.1') # Prepare the email data data = { 'Messages': [ { "From": { "Email": "pilot@mailjet.com", # Must be a verified sender in your Mailjet account "Name": "Mailjet Pilot" }, "To": [ { "Email": "passenger@mailjet.com", "Name": "Passenger 1" } ], "Subject": "Your email flight plan!", "TextPart": "Dear passenger, welcome to Mailjet! May the delivery force be with you!", "HTMLPart": "<h3>Dear passenger, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!" } ] } # Send the email result = mailjet.send.create(data=data) # Print the response status and content print(f"Status Code: {result.status_code}") print(f"Response: {result.json()}") # Check for common API errors if result.status_code >= 400: print(f"Error details: {result.json()}")
Debug
Known issues
breakingSupport for Python 3.9 was dropped in mailjet-rest v1.5.0. Ensure your environment uses Python 3.10 or newer for full compatibility and continued updates.
fix
Upgrade your Python environment to 3.10 or a later supported version.
affects: >=1.5.0
gotchaPrior to v1.5.0, users experienced `csvimport error 'List index (0) out of bounds'` when attempting CSV imports. This was fixed in v1.5.0.
fix
Upgrade to mailjet-rest v1.5.0 or later to resolve CSV import issues.
affects: <1.5.0
gotchaIncorrect Mailjet API keys (public and private) will lead to `401 Unauthorized` errors. Always double-check your credentials and ensure they are active.
fix
Verify your API keys on your Mailjet account dashboard and ensure they are correctly configured in your application.
affects: All
gotchaMailjet API PUT requests behave like PATCH requests, meaning they only update the specified properties and do not overwrite the entire resource. Other existing properties will remain unchanged.
fix
Be aware that PUT operations are partial updates. Only include the fields you intend to modify in your payload.
affects: All
gotchaMailjet's API has rate limits (e.g., typically 30 calls/second for some endpoints). Exceeding these limits will result in `429 Too Many Requests` errors.
fix
Implement retry logic with exponential backoff and consider using batch sending for high volumes of emails to stay within rate limits.
affects: All
gotchaThe `Recipients` property in the email payload sends a separate, individualized message to each recipient without revealing other recipients. In contrast, `To`, `Cc`, and `Bcc` will show other recipients as expected in a standard email client. Mixing `Recipients` with `To`, `Cc`, or `Bcc` is not allowed.
fix
Choose either `Recipients` for individual, hidden messages or `To`/`Cc`/`Bcc` for group visibility, but do not combine them in a single send request.
affects: All
Errors
Common errors & fixes
Unsuccessful: Status Code: "401" Message: "API key authentication/authorization failure. You may be unauthorized to access the API or your API key may be expired. Visit API keys management section to check your keys."
The Mailjet API Key or Secret Key provided for authentication are incorrect, expired, lack necessary permissions, or are being confused with your Mailjet account login credentials.
fix
Verify your API Key and Secret Key in your Mailjet account's API Key Management section, ensure they are active and have the required permissions, then correctly initialize the `mailjet-rest` client with these keys.
```python
from mailjet_rest import Client

api_key = 'YOUR_MAILJET_API_KEY' # Replace with your actual Public API Key
api_secret = 'YOUR_MAILJET_API_SECRET' # Replace with your actual Secret API Key

mailjet = Client(auth=(api_key, api_secret), version='v3.1') # Use v3.1 for sending emails
```
MJ-009
This error code indicates that the 'From' email address specified in your email sending request is either not registered or not verified in your Mailjet account.
fix
Log into your Mailjet account, navigate to the Sender Emails section, verify the email address you intend to use as the sender, and ensure it's included correctly in your API request payload as a verified sender.
```python
# Assuming 'mailjet' client is already initialized
message_data = {
    'Messages': [
        {
            'From': {
                'Email': "your_verified_email@example.com", # Must be a verified sender in your Mailjet account
                'Name': "Your Name"
            },
            'To': [
                {
                    'Email': "recipient@example.com",
                    'Name': "Recipient Name"
                }
            ],
            'Subject': "My first Mailjet Email!",
            'TextPart': "Greetings from Mailjet!",
            'HTMLPart': "<h3>Dear passenger, welcome to <a href=\"https://www.mailjet.com/\">Mailjet</a>!</h3><br />May the delivery force be with you!"
        }
    ]
}
result = mailjet.send.create(data=message_data)
```
ImportError: No module named requests
The `requests` library, a fundamental dependency for `mailjet-rest` to make HTTP calls, is not installed in your Python environment.
fix
Install the `requests` library using pip. If `mailjet-rest` was installed without its dependencies for some reason, reinstall `mailjet-rest` to ensure all its requirements are met.
```bash
pip install requests
# Or, to ensure mailjet-rest and its dependencies are properly installed/updated
pip install --upgrade mailjet-rest
```
400 Bad Request. One or more parameters are missing or maybe misspelled (unknown resource or action).
The request payload (the Python dictionary representing your data) sent to the Mailjet API is improperly formatted, missing required fields, or contains incorrect data types or values for the specific API endpoint you are trying to use.
fix
Carefully review the official Mailjet API documentation for the specific endpoint you are targeting (e.g., Send API v3.1, Contact management) and ensure your Python dictionary exactly matches the expected JSON structure and parameter requirements, including all mandatory fields and correct data types.
```python
# Corrected example for sending an email (ensure all required fields are present and correct)
# Assuming 'mailjet' client is already initialized
message_data = {
    'Messages': [
        {
            'From': {
                'Email': "your_verified_email@example.com",
                'Name': "Your Name"
            },
            'To': [
                {
                    'Email': "recipient@example.com",
                    'Name': "Recipient Name"
                }
            ],
            'Subject': "Your Email Subject", # Required field for email sending
            'TextPart': "Your email text content.", # Either TextPart or HTMLPart is required
            # 'HTMLPart': "<h3>Your <b>HTML</b> content.</h3>"
        }
    ]
}
result = mailjet.send.create(data=message_data)
```
Upgrade
Version history
1.8.0latest on PyPI · released Aug 17, 2026
Audit
Dependencies
requestsrequiredRequired for making HTTP requests to the Mailjet API.
pythonrequiredRequires Python 3.10 or newer.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
mailjet-rest — pip install mailjet-rest · libregistry