mailhog-python
A python client for the Mailhog API
Installation
Install from PyPI
pip install mailhog
Get Started
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])
API
mailhog.Mailhog
Mailhog API client
Parameters
host- The host of the Mailhog API, defaults tolocalhostport- The port of the Mailhog API, defaults to8025
Methods
messages(start=0, limit=10)
Get all messages
Parameters
start- The start index of the messages to return, defaults to0limit- The number of messages to return, defaults to10
Returns
list- A list ofmailhog.Messageobjects
Example
from mailhog import Mailhog
mailhog = Mailhog()
messages = mailhog.messages()
search(query, kind='containing', start=0, limit=10)
Search for messages
Parameters
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
Returns
list- A list ofmailhog.Messageobjects
Example
from mailhog import Mailhog
mailhog = Mailhog()
messages = mailhog.search('Some Text')
delete_all()
Delete all messages
Example
from mailhog import Mailhog
mailhog = Mailhog()
mailhog.delete_all()
delete()
Delete a message
Example
from mailhog import Mailhog
mailhog = Mailhog()
messages = mailhog.messages()
mailhog.delete(messages.items[0])
Datatypes
mailhog.Messages
A list of
mailhog.Messageobjects
Attributes
total- The total number of messagesstart- The start index of the messagescount- The total number of received messagesitems- A list ofmailhog.Messageobjects
mailhog.Message
A message from Mailhog
Attributes
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
Methods
get_sender()
Get the sender of the message
Returns
str- The sender of the message
get_recipients()
Get the recipients of the message
Returns
list- A list of recipients
get_subject()
Get the subject of the message
Returns
str- The subject of the message
mailhog.Path
A path object
Attributes
relays- A list of relaysmailbox- The mailboxdomain- The domainparams- The parameters
mailhog.Content
The content of a message
Attributes
headers- A Dict of headers of the messagebody- The body of the messagesize- The size of the messagemime- The MIME type of the message
mailhog.MIMEBody
The body of a MIME message
Attributes
parts- A list of mailhog.MIMEContent objects
mailhog.MIMEContent
The content of a MIME message
Attributes
headers- A Dict of headers of the messagebody- The body of the messagesize- The size of the messagemime- The MIME type of the message
About the Package
WIP
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
Roadmap
- 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
Local Development
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
Metadata
Release files for mailhog 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mailhog-0.1.1.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mailhog-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.3 kB
Release files / mailhog-0.1.1.tar.gz
| Download URL | mailhog-0.1.1.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ab4e9662ee2ae1a73493c208df53d4f2ae3b1c5120648129d2a97a14eea4a93
|
|
BLAKE2b-256 checksum How to use checksums |
414527db1a209cda3512362c95e5d6236b307592ab4668e11371b24c3ae75794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.13 Linux/6.5.0-1018-azure
|
Release files / mailhog-0.1.1-py3-none-any.whl
| Download URL | mailhog-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9e798b4cbdab8df87bb23ba9e39bd67c1e9026e1020f05d1e045afda708429f
|
|
BLAKE2b-256 checksum How to use checksums |
8e752b479d173107ad69e553011264542ce0109156b0db6c2656b1ad4b27c2f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.13 Linux/6.5.0-1018-azure
|