Integrations

Python

Official Python client for sending emails and managing contacts, templates, and more.

How it works

Integrate a complete email sending and sandbox solution into your Python projects with the official SDK. Send from transactional or bulk streams, manage contacts, suppression lists, templates, and your account – all while benefiting from high deliverability rates and actionable analytics insights.

Configure

  1. Create a Mailtrap account and verify your domain. 
  2. Install Mailtrap package via pip install mailtrap
  3. Send emails, below you’ll find minimal usage example.
import mailtrap as mt

API_TOKEN = "<YOUR_API_TOKEN>"  # your API key here https://mailtrap.io/api-tokens

client = mt.MailtrapClient(token=API_TOKEN)

# Create mail object
mail = mt.Mail(
    sender=mt.Address(email="sender@example.com", name="John Smith"),
    to=[mt.Address(email="recipient@example.com")],
    subject="You are awesome!",
    text="Congrats for sending test email with Mailtrap!",
)

client.send(mail) 

For more information on advanced usage and easy switching between sandbox and production environments, check the official SDK documentation

Supported functionality

  • Transactional and bulkemail sending (with or without templates)
  • Batch email sending (with or without templates)
  • Template management
  • Contact management
  • Sandbox testing
  • Suppressions management
  • Account management