Email API for Python
A reliable Python email API for straightforward transactional email delivery.

Easy integration with your Python app
from mailersend import emails
mailer = emails.NewEmail()
mail_body = {}
mail_from = {
"name": "Your Name",
"email": "your@domain.com",
}
recipients = [
{
"name": "Your Client",
"email": "your@client.com",
}
]
mailer.set_mail_from(mail_from, mail_body)
mailer.set_mail_to(recipients, mail_body)
mailer.set_subject("Hello!", mail_body)
mailer.set_html_content("Greetings from the team, you got this message through MailerSend.", mail_body)
mailer.set_plaintext_content("Greetings from the team, you got this message through MailerSend.", mail_body)
mailer.send(mail_body)

SMTP support when you need it
Fast, secure, reliable SMTP server for developers who prefer to use Python’s built-in smtplib module or Flask-Mail, or need SMTP credentials for use with legacy systems.
Everything you need to start sending
API reference
An in-depth guide to MailerSend API features and endpoints.
GitHub repository
The official MailerSend Python SDK with code snippets you can use to start sending.
Developer guide
Our technical guide to setting up the MailerSend Python email API SDK and sending your first email.
Python help article
An in-depth article with clear examples for sending different emails with Python via API or SMTP.

Flexible inbound email processing
MailerSend's inbound routes let you receive emails and attachments, forwarding JSON-parsed email content to an API endpoint or email address.
From static to smart with dynamic email templates
from mailersend import emails
from dotenv import load_dotenv
load_dotenv()
mailer = emails.NewEmail(os.getenv('MAILERSEND_API_KEY'))
# define an empty dict to populate with mail values
mail_body = {}
mail_from = {
"name": "Your Name",
"email": "your@domain.com",
}
recipients = [
{
"name": "Your Client",
"email": "your@client.com",
}
]
variables = [
{
"email": "your@client.com",
"substitutions": [
{
"var": "foo",
"value": "bar"
},
]
}
]
mailer.set_mail_from(mail_from, mail_body)
mailer.set_mail_to(recipients, mail_body)
mailer.set_subject("Hello from {$company}", mail_body)
mailer.set_template("templateID", mail_body)
mailer.set_personalization(variables, mail_body)
mailer.send(mail_body)

Better email management with real-time validation API
Immediately verify email addresses upon entry by checking for SMTP responses, valid MX records, disposable domains and more. Flag or block invalid emails and provide real-time user feedback.
Debugging made easy
-
Activity monitoring
Catch potential issues early on: from queued to clicked, see the status of every message sent in the real-time activity dashboard. -
Webhook notifications
Receive alerts about email activity such as bounces and spam complaints as they happen. -
API & SMTP logs
Get full visibility into every request and easily find errors in the searchable logs.



Whatever the use case, we’ve got the endpoint
Send order confirmations, password resets, OTPs and more.
/bulk-email
Send service updates, event reminders, and account summaries.
/activity
Create custom dashboards or integrate activity metrics into other apps.
/analytics
Automate reports, pull data into internal tools, or trigger conditional logic.
/domains
Automate domain setup and get an overview of active domains.
/inbound
Manage inbound routes and create user-specific routes on signup.
/recipients
Share recipient data across tools to sync contacts and manage suppressions.
/templates
Send with email templates that look professional and contain dynamic content.
/email-verification
Configure forms to perform real-time email validation or verify a whole list.
/sms
Send appointment reminders, 2FA messages, shipping updates and more.
/smtp-users
Programmatically create SMTP users during environment setup.
View more endpoints

Technical support when you need it
Our friendly and knowledgeable customer support team looks at each and every case, always aiming to provide the best solutions in record time. Get help via email or live chat.
Dev-approved, team-friendly
Explore all features
Analytics

Access a wide range of key metrics in MailerSend’s email analytics dashboard to track deliverability and engagement and improve overall email performance.
Drag & drop builder

Build professional emails with our no-code, drag & drop editor.
HTML builder

Code custom, responsive, and dynamic emails with our HTML editor.
A/B testing

Split test your templates to see what content works best and drive higher overall engagement.
User management

Invite team members and manage user permissions for easy collaboration.
Suppressions management

Effortlessly protect your sender reputation and preserve your sending quota with automatic email exclusions and user-friendly suppression list management.
And much more to deliver, every single time
Meet our SDKs
Start sending now for free
Send your first email in minutes with a trial domain and subscribe to the Hobby plan for up to 3,000 emails/month free.
Frequently asked questions
How do I get started with MailerSend's Python SDK?
To get started with the Python SDK, sign up for a free account and create your API key. You can then install the MailerSend package using pip and use our Github documentation for code examples.
Is there a free tier for testing the API?
Yes, our free trial includes 100 emails and a demo domain you can use to quickly test out the API and sending functionality.
How do I handle attachments in Python?
To add attachments to email messages, you need to set the attachment in your code. Check out our SDK documentation on sending an email with an attachment.
Can I use MailerSend with popular Python web frameworks like Django or Flask?
Yes, you can use MailerSend with popular Python frameworks.
How can I view errors?
You can configure you system to return the full response when you make a request or, if you have a Professional or Enterprise plan, you can view errors on the SMTP and API Logs page.
What are the prerequisites for using the Python SDK?
To use the Python SDK, you’ll need Python 3.6.1 or higher, pip, a MailerSend account, and a MailerSend API key.
Can I use templates created in MailerSend with the Python SDK?
Yes, you can simply enter the template ID into your code. Find out more in our SDK documentation.
Does the Python SDK support bulk email sending?
Yes, you can send email in bulk with the bulk email endpoint.
How do I verify my sending domain?
You can add and verify domain via API or, from the dashboard, go to Email > Domains > Add domain. You cansave time and complete automatic domain authentication by following the steps, or verify your domain manually by adding the DNS records.