A python client for the Mailhog API
Install from PyPI
pip install mailhog from mailhog import Mailhog mailhog = Mailhog() # Defaults to http://localhost:8025 # Get all messages mailhog.messages() # Get all messages with start and limit parameters mailhog.messages(start=0, limit=10) # Search for messages mailhog.search('Text contained in the message') # Search for messages by recipient mailhog.search('test@test.com', 'To') # Search for messages by sender mailhog.search('test@test.com', 'From') # Delete all messages mailhog.delete_all() # Delete a message mailhog.delete(messages.items[0])Mailhog API client
host- The host of the Mailhog API, defaults tolocalhostport- The port of the Mailhog API, defaults to8025
Get all messages
start- The start index of the messages to return, defaults to0limit- The number of messages to return, defaults to10
list- A list ofmailhog.Messageobjects
from mailhog import Mailhog mailhog = Mailhog() messages = mailhog.messages()Search for messages
query- The query to search forkind- The kind of search to perform, defaults tocontainingstart- The start index of the messages to return, defaults to0limit- The number of messages to return, defaults to10
list- A list ofmailhog.Messageobjects
from mailhog import Mailhog mailhog = Mailhog() messages = mailhog.search('Some Text')Delete all messages
from mailhog import Mailhog mailhog = Mailhog() mailhog.delete_all()Delete a message
from mailhog import Mailhog mailhog = Mailhog() messages = mailhog.messages() mailhog.delete(messages.items[0])A list of
mailhog.Messageobjects
total- The total number of messagesstart- The start index of the messagescount- The total number of received messagesitems- A list ofmailhog.Messageobjects
A message from Mailhog
id- The ID of the messagefrom_- A mailhog.Path object containing the senderto- A List of mailhog.Path objects containing the recipientscreated- The date the message was createdcontent- A mailhog.Content object containing the content of the messageraw: - The raw messagemime- A mailhog.MIME object containing the MIME data of the message
Get the sender of the message
str- The sender of the message
Get the recipients of the message
list- A list of recipients
Get the subject of the message
str- The subject of the message
A path object
relays- A list of relaysmailbox- The mailboxdomain- The domainparams- The parameters
The content of a message
headers- A Dict of headers of the messagebody- The body of the messagesize- The size of the messagemime- The MIME type of the message
The body of a MIME message
parts- A list of mailhog.MIMEContent objects
The content of a MIME message
headers- A Dict of headers of the messagebody- The body of the messagesize- The size of the messagemime- The MIME type of the message
This package is still a work in progress. If you find any bugs or have any suggestions, please open an issue on the GitHub repository
- Mailhog API v2 Messages Endpoint
- Mailhog API v2 Search Endpoint
- Mailhog API v2 Jim Endpoint
- Mailhog API v1 Delete Messages Endpoint
- Mailhog API v1 Delete Message Endpoint
To install the package locally, run the following commands:
git clone cd mailhog-python poetry install To run a mailhog instance locally, run the following command:
docker-compose up -d To run the tests, run the following command:
poetry run pytest