Skip to main content

Simple SMTP server for testing mailing code.

Project description

# MailMitt

MailMitt is a tool for performing regression testing on email delivery code.
It allows applications to send emails to an SMTP server without actual emails
being delivered to anyone.

It also provides both a web interface and a RESTful JSON API for reviewing the
content of the emails that you send.

Nothing is actually delivered, and any emails that MailMitt receives are just
stored in memory.

It is inspired by https://github.com/ThiefMaster/maildump, although it is
re-written from the ground up using an asyncio-based event loop rather than gevent.

Because of this, it only runs on Python 3.5 and above, whereas MailDump only runs on
Python 2.

## Installation


```bash
pip3 install mailmitt
```

## Usage

`mailmitt --help`

produces a list of available command line arguments.

By default mailmitt runs its webserver on port
1080 and its SMTP server on port 1025 (both only available via localhost). If
you want to access it from another machine, use something like this:

`mailmitt --http-ip 0.0.0.0 --smtp-ip 0.0.0.0`


## API


`GET http://localhost:1080/messages`

* Gets all emails, including their content, as a JSON tree.

`GET http://localhost:1080/messages/0.source`

* Gets the source for the first email. Replace `0` with the index of the email you wish to retrieve

`GET http://localhost:1080/messages/0.plain`

* Gets the plaintext version of the first email.

`GET http://localhost:1080/messages/0.html`

* Gets the HTML version of the first email if it exists.

`GET http://localhost:1080/messages/0.json`

* Gets a JSON representation of the first email.

`DELETE http://localhost:1080/messages`

* Deletes all emails from memory


## Sample Usage

Run this in one terminal:
```bash
mailmitt
```

And then in a python3 session:

```python
import requests
import smtplib
from email.message import EmailMessage

message = EmailMessage()
message['Subject'] = "Sample Subject"
message['To'] = "to@example.com"
message['From'] = "from@example.com"

message.set_content("""\
Hello
This is a sample email
""")

message.add_alternative("""
<h1>Hello</h1>
<p>This is a sample email</p>
""", subtype='html')

with smtplib.SMTP('localhost',port=1025) as smtp:
smtp.sendmail(message['From'],message['To'],message.as_string())

print(requests.get('http://localhost:1080/messages/0.plain').text.strip())
```


Although this example is in Python, MailMitt can be accessed from SMTP client
libraries in any language.

```
Hello
This is a sample email
```

## Webserver
You will also be able to review your emails at http://localhost:1080/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailmitt-0.0.4.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mailmitt-0.0.4-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file mailmitt-0.0.4.tar.gz.

File metadata

  • Download URL: mailmitt-0.0.4.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/3.6.6

File hashes

Hashes for mailmitt-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9a9f7f1c49c6241d4b0c327a8302ec011d374ad56b1ebdc62fc00a9409ae91f6
MD5 39582b38a33d381219c0ce6e4f03ac5c
BLAKE2b-256 4ea17c773e36231fa12157e8d5d66a8be693c46b68c4a1f0800df8adf5ac4237

See more details on using hashes here.

File details

Details for the file mailmitt-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: mailmitt-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.10.0 pkginfo/1.2.1 requests/2.18.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.19.4 CPython/3.6.6

File hashes

Hashes for mailmitt-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4bda08171073bf3ec8872fcc3f094b82b26205bad6a1124dac21a91740b07698
MD5 c2192b5982a6a346ce4be2a42f4447af
BLAKE2b-256 0c912d1dcf4a9713a53c969b9fd6eecb127b830fcd3f186ebbe0986abc2e80ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page