Skip to main content

SMTP Server with API for email testing inspired by mailtrap and maildump

Project description

https://travis-ci.org/reclosedev/lathermail.svg?branch=master https://coveralls.io/repos/reclosedev/lathermail/badge.svg?branch=master&service=github

lathermail

SMTP Server with API for email testing inspired by mailtrap and maildump

Can store messages in MongoDB or any SQLAlchemy supported DB (e.g., sqlite). Supports Python 2.7, 3.4, 3.5, pypy.

Usage:

$ virtualenv venv  # or mkvirutalenv lathermail
$ . venv/bin/activate
$ pip install lathermail
$ lathermail --help

usage: lathermail [-h] [--db-uri DB_URI] [--api-host API_HOST]
                  [--api-port API_PORT] [--smtp-host SMTP_HOST]
                  [--smtp-port SMTP_PORT]

optional arguments:
  -h, --help            show this help message and exit
  --db-uri DB_URI       DB URI, e.g. mongodb://localhost/lathermail,
                        sqlite:////tmp/my.db (default:
                        sqlite:///~/.lathermail.db)
  --api-host API_HOST   API Host (default: 127.0.0.1)
  --api-port API_PORT   API port (default: 5000)
  --smtp-host SMTP_HOST
                        SMTP host (default: 127.0.0.1)
  --smtp-port SMTP_PORT
                        SMTP port (default: 2525)

It will start SMTP server and API server in single process.

Inboxes are identified by SMTP user/password pairs. lathermail intended to be used in single project environment.

To send email, just use SMTP client with auth support.

API

To request API, you must provide headers:

  • X-Mail-Password - same as SMTP password

  • X-Mail-Inbox - same as SMTP user. Optional, work with all inboxes if not specified

GET /api/0/inboxes/

Returns list of inboxes for passed X-Mail-Password:

{
    "inbox_list": [
        "first",
        "second",
        "third"
    ],
    "inbox_count": 3
}

GET /api/0/messages/<message_id>

Returns single message. Example:

{
    "message_info": {
        "message_raw": "Content-Type: multipart/mixed; boundary=\"===============3928630509694630745==...",
        "password": "password",
        "sender": {
            "name": "Me",
            "address": "asdf@exmapl.com"
        },
        "recipients": [
            {
                "name": "Rcpt1",
                "address": "rcpt1@example.com"
            },
            {
                "name": "Rcpt2",
                "address": "rcpt2@example.com"
            },
            {
                "name": "",
                "address": "rcpt3@example.com"
            }
        ],
        "recipients_raw": "=?utf-8?q?Rcpt1?= <rcpt1@example.com>,\n =?utf-8?q?Rcpt2?= <rcpt2@example.com>, rcpt3@example.com",
        "created_at": "2014-06-24T15:28:35.045000+00:00",
        "sender_raw": "Me <asdf@exmapl.com>",
        "parts": [
            {
                "index": 0,
                "body": "you you \u043f\u0440\u0438\u0432\u0435\u0442 2",
                "is_attachment": false,
                "charset": "utf-8",
                "filename": null,
                "type": "text/plain",
                "size": 16
            },
            {
                "index": 1,
                "body": null,
                "is_attachment": true,
                "charset": null,
                "filename": "t\u0430\u0441\u0434est.txt",
                "type": "application/octet-stream",
                "size": 12
            }
        ],
        "inbox": "inbox",
        "_id": "53a960e3312f9156b7c92c5b",
        "subject": "Test subject \u0445\u044d\u043b\u043b\u043e\u0443 2",
        "read": false
    }
}

Attachments in message have body = null. To download file, use following method.

GET /api/0/messages/<message_id>/attachments/<attachment_index>

Returns file from message. Works in browsers.

GET /api/0/messages/

Returns messages according to optional filters:

  • sender.name - Name of sender

  • sender.address - Email of sender

  • recipients.name - Name of any of recipients

  • recipients.address - Email of any of recipients

  • subject - Message subject

  • subject_contains - Any part of message subject

  • created_at_lt - Filter messages created before this ISO formatted datetime

  • created_at_gt - Filter messages created after this ISO formatted datetime

  • read - Return only read emails when True or unread when False. All emails returned by default

Example:

{
    "message_count": 3,
    "message_list": [
        {"_id": ..., "parts": [...], ...},  // same as single message
        {...},
        {...}
    ]
}

DELETE /api/0/messages/<message_id>

Deletes single message

DELETE /api/0/messages/

Deletes all messages in inbox. Also, you can filter deletable messages like in GET /api/0/

Configuration

Copy lathermail.conf.example, modify it, export environment variable before starting:

$ export LATHERMAIL_SETTINGS=/path/to/lathermail.conf
$ lathermail

To run tests:

$ python -m tests

Changelog

0.3.0 (2016-09-01)

  • HTML multipart support (#2, #3)

  • Fix multipart binary messages

Project details


Download files

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

Source Distributions

lathermail-0.3.0.zip (30.3 kB view details)

Uploaded Source

lathermail-0.3.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

lathermail-0.3.0-py2-none-any.whl (26.1 kB view details)

Uploaded Python 2

File details

Details for the file lathermail-0.3.0.zip.

File metadata

  • Download URL: lathermail-0.3.0.zip
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lathermail-0.3.0.zip
Algorithm Hash digest
SHA256 b601769b54fa54a9b7d34401bb53dad1b728a43b3d3954ed3115e6eb61d41985
MD5 041da46bef40af6ea41cde5f6d5c8049
BLAKE2b-256 87bd30899070f89e875e1999d2ffc477ccdc7ec4fa47a902d34202c0d26a3124

See more details on using hashes here.

File details

Details for the file lathermail-0.3.0.tar.gz.

File metadata

  • Download URL: lathermail-0.3.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lathermail-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f9d221d9f75cabfd06bb466de94620ff4f7820c7f319eb0acf8a70ce93c0f89e
MD5 866af675fe4f01ea93bdffd66e82979e
BLAKE2b-256 8ef13925aaf63901e1edde0ffea0e3101afa06c0ebee4f1c6ba82c04705320ca

See more details on using hashes here.

File details

Details for the file lathermail-0.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for lathermail-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 c99a451c7498b3c5c62554e57cec559878193a07ac5cd837601e95702b298ffd
MD5 63cad30ad70ab2925824be927fdb464e
BLAKE2b-256 e06ae094da6fb7d8882837a4a175f9f481a55c3c9be5248da51d416508725e7c

See more details on using hashes here.

Supported by

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