Getting started overview

Integrating with Mailjet for email services involves a series of steps that enable programmatic email sending. The process begins with establishing a Mailjet account, which provides access to the platform's features and API credentials. Once an account is active, developers generate API keys that function as authentication tokens for all API interactions. These keys are crucial for securing requests and identifying the sender. The final step in the initial setup is making a successful API call, typically a simple email send request, to verify the integration and confirm that the API keys are correctly configured and operational. This foundational process ensures that subsequent development using the Mailjet API can proceed without authentication or connectivity issues.

Mailjet supports various programming languages through official SDKs, including Mailjet PHP SDK installation, Mailjet Python SDK guide, Mailjet Node.js SDK setup, and Mailjet Java SDK documentation. These SDKs abstract the underlying HTTP requests, simplifying interaction with the API. Alternatively, direct HTTP requests using tools like cURL are also supported for environments where SDKs are not preferred or available. The Mailjet API follows a RESTful architecture, utilizing JSON for request and response bodies, as detailed in the Mailjet API reference.

Here's a quick reference table for the essential steps:

Step What to do Where
1. Sign Up Create a new Mailjet account Mailjet Signup Page
2. Verify Email Confirm your email address Your email inbox
3. Locate API Keys Find your API Key and Secret Key Mailjet API Keys Management
4. Configure Sender Domain Add and verify your sending domain Mailjet Sender Domains
5. Make First Request Send a test email using the API Your development environment (using cURL or an SDK)

Create an account and get keys

To begin using Mailjet, account creation is the initial requirement. Navigate to the official Mailjet signup page. The registration process typically involves providing an email address and creating a password. After submission, Mailjet sends a verification email to the address provided. It is necessary to click the link within this email to activate the account and confirm ownership. This step helps secure the account and ensures deliverability for future communications.

Once your account is active, log in to the Mailjet dashboard. API keys are essential for authenticating requests to the Mailjet API. These keys consist of two parts: an API Key and a Secret Key. To locate these credentials, navigate to the API Keys section within your account settings. Mailjet uses these keys for HTTP Basic Authentication, where the API Key serves as the username and the Secret Key as the password. It is crucial to treat these keys as sensitive information, similar to passwords, to prevent unauthorized access to your email sending capabilities. For security best practices, avoid embedding keys directly in code and instead use environment variables or a secure configuration management system.

Before sending emails, it is also recommended to configure and verify your sending domain. This process involves adding your domain in the Mailjet dashboard under Sender Domains and then configuring DNS records (TXT, MX, SPF, DKIM) as instructed by Mailjet. Domain verification improves email deliverability and helps prevent emails from being flagged as spam by recipient servers, as outlined in Mailjet's guide to email deliverability.

Your first request

After acquiring your API Key and Secret Key, the next step is to make a test API call to ensure everything is configured correctly. This example demonstrates sending a simple transactional email using the Mailjet API v3.1. The API endpoint for sending emails is https://api.mailjet.com/v3.1/send. The request body is a JSON object containing details about the email, such as sender, recipients, subject, and content.

Below is a cURL example for sending a basic email. Replace YOUR_API_KEY and YOUR_SECRET_KEY with your actual Mailjet credentials. Also, update [email protected], sender_name, [email protected], and recipient_name with appropriate values. Ensure your sender email address is associated with a verified domain in your Mailjet account.

curl -s \ 
  -X POST \ 
  --user "YOUR_API_KEY:YOUR_SECRET_KEY" \ 
  https://api.mailjet.com/v3.1/send \ 
  -H 'Content-Type: application/json' \ 
  -d '{ 
    "Messages":[ 
      { 
        "From": { 
          "Email": "[email protected]", 
          "Name": "Sender Name" 
        }, 
        "To": [ 
          { 
            "Email": "[email protected]", 
            "Name": "Recipient Name" 
          } 
        ], 
        "Subject": "My first Mailjet email!", 
        "TextPart": "Greetings from Mailjet!", 
        "HTMLPart": "

Dear passenger, welcome to Mailjet!


May the delivery force be with you!", "CustomID": "GettingStarted" } ] }'

Upon successful execution, the Mailjet API will return a JSON response similar to this, indicating that the email has been accepted for processing:

{
  "Messages": [
    {
      "Status": "success",
      "CustomID": "GettingStarted",
      "To": [
        {
          "Email": "[email protected]",
          "MessageUUID": "some_uuid_string",
          "MessageID": 12345678901234567,
          "MessageHref": "https://api.mailjet.com/v3/message/12345678901234567"
        }
      ]
    }
  ]
}

The Status: "success" indicates that Mailjet has received and accepted your email request. You can check the email's delivery status within your Mailjet account dashboard under the Campaigns & Statistics section. If you encounter issues, verify your API keys, sender email, and the JSON structure of your request.

Common next steps

After successfully sending your first email, several common next steps can enhance your Mailjet integration:

  1. Explore SDKs: While cURL is useful for testing, using one of Mailjet's official SDKs (PHP, Python, Node.js, Java, Ruby, Go) can simplify development. SDKs handle authentication, request formatting, and response parsing, reducing boilerplate code. Refer to the Mailjet API Getting Started guides for specific language implementations.
  2. Implement Webhooks: To receive real-time notifications about email events (e.g., delivered, opened, clicked, bounced), configure webhooks. This allows your application to react to email status changes without constantly polling the API. Mailjet provides comprehensive documentation on Mailjet webhook setup. For general webhook security, consult resources like Twilio's webhook security guide.
  3. Create and Use Templates: For consistent branding and easier email management, create email templates within the Mailjet dashboard. You can inject dynamic content into these templates using variables when sending emails via the API. This separates content from code and allows non-developers to manage email designs. Learn more about Mailjet's templating language.
  4. Manage Contacts and Lists: For marketing campaigns, utilize Mailjet's contact management features to create and manage contact lists. The API allows programmatic addition, removal, and updating of contacts. Refer to the Mailjet Contact API documentation.
  5. Monitor Deliverability: Regularly monitor your email deliverability statistics within the Mailjet dashboard. This includes open rates, click rates, bounce rates, and spam complaints. High bounce rates or spam complaints can negatively impact your sender reputation. Mailjet offers tools and analytics to help maintain good deliverability, as detailed in their Mailjet deliverability best practices.
  6. Explore Advanced Features: Mailjet offers advanced features like A/B testing for marketing emails, segmentation, and detailed analytics. Investigate these options based on your specific use cases to optimize your email strategy.
  7. Review Pricing and Plan: As your email volume grows, review Mailjet's pricing plans to ensure your current plan meets your needs and budget. The free tier is suitable for initial testing and low-volume sending (200 emails/day or 6,000 emails/month).

Troubleshooting the first call

Encountering issues during your initial API call is common. Here are some troubleshooting steps and common problems:

  • Authentication Errors (401 Unauthorized):
    • Incorrect API Keys: Double-check that you are using the correct API Key and Secret Key from your Mailjet account. Ensure there are no typos or extra spaces. Remember the API Key is the username and the Secret Key is the password for Basic Authentication.
    • Key Permissions: Verify that the API keys you are using have the necessary permissions to send emails. New keys typically have full access, but custom-generated keys might have restricted permissions.
  • Bad Request (400 Bad Request):
    • Malformed JSON: Ensure your JSON request body is syntactically correct. Use a JSON linter to validate its structure. Common errors include missing commas, unclosed brackets, or incorrect data types.
    • Missing Required Fields: Check the Mailjet Send API documentation for required fields like From.Email, To.Email, and Subject.
    • Invalid Email Address Format: Ensure all email addresses in your request (From, To) are valid and correctly formatted.
  • Forbidden (403 Forbidden):
    • Unverified Sender Domain/Email: Mailjet requires that the sender email address (From.Email) be associated with a verified domain or be a verified sender email in your account. If the domain is not verified, emails will be rejected. Go to Mailjet Sender Domains to verify your domain.
    • Account Restrictions: In rare cases, new accounts might have temporary sending limits or restrictions until certain verification steps are completed. Check your Mailjet dashboard for any active alerts or pending verifications.
  • Server Error (5xx Server Error):
    • These typically indicate an issue on Mailjet's side. While less common, if you receive a 5xx error, it's advisable to check the Mailjet Status Page for any ongoing service disruptions. If no issues are reported, contact Mailjet support with your request details.
  • Network Connectivity:
    • Ensure your development environment has stable internet connectivity and is not blocked by a firewall from accessing api.mailjet.com.

When troubleshooting, always examine the API response body carefully, as it often contains specific error messages that can guide you to the root cause. The Mailjet API error codes documentation provides details on common error responses.