Python email API - send and receive email in code and tests
Send and receive email in Python, create test email accounts and more with the official PyPI MailSlurp package.
Create real email addresses in Python for testing and development. No need for SMTP mail servers, use MailSlurp's free email API and PyPI package to send and receive email for real inboxes. Test applications end-to-end with Robotframework, Selenium, Pytest and more. Integrates with Django, Flask, and many popular frameworks.
Installing Python library
MailSlurp python email library is available from PyPI:
pip install mailslurp-client
Once install configure a client instance in your project using your MailSlurp API key.
import mailslurp_client configuration = mailslurp_client.Configuration() configuration.api_key['x-api-key'] = "your-api-key-here"
To create an email address use the inbox controller:
Use with statements to create controllers for each endpoint of the MailSlurp API. def create_inbox_example(): with mailslurp_client.ApiClient(configuration) as api_client: # create an inbox using the inbox controller api_instance = mailslurp_client.InboxControllerApi(api_client) inbox = api_instance.create_inbox() # check the id and email_address of the inbox assert len(inbox.id) > 0 assert "mailslurp.com" in inbox.email_address
To get started create a free email account and read the documentation and links below: