SMTP4DEV

An abstraction library to access the messages captured by an SMTP4dev instance.

Installation

Install with:

pip install smtp4dev

Dependencies

This library depends on having a working SMTP4Dev server. This can either be running locally, or remotely, or in a Docker container.

Usage

A brief introduction to the basic usage of the library. See the API documentation for more details.

Client

All API connectivity is abstracted behind a client. This allows listing and retrieval of emails. Example:

from smtp4dev import Smtp4Dev
client = Smtp4Dev('http://localhost:8080')
messages = client.list_messages()

Message

Message is the abstraction of an Email. They contain the following properties:

  • sender
  • recipients
  • received_date
  • subject
  • body

Example usage

from smtp4dev import Smtp4Dev
client = Smtp4Dev('http://localhost:8080')
messages = client.list_messages()

for message in messages:
    print("from {}: {}".format(message.sender, message.subject))

API

This part of the documentation covers all the interfaces for smtp4dev.

Main Client Object

class smtp4dev.Smtp4Dev(base_url)

API client for SMTP4dev.

get_message(msg_id)

Retrieve a specific message by ID.

Parameters:msg_id – the messages’s pk (a UUID)
Returns:a Message instance
Raises:ApiError
list_messages(unread_only=False)

List all messages in the smtp4dev inbox.

Parameters:unread_only – Only retrieve the unread messages
Returns:a generator of Message items
Raises:ApiError
mark_message_read(msg_id)

Mark a message a read in the inbox.

Parameters:msg_id – the message’s pk (a UUID)
Raises:ApiError

Message Object

class smtp4dev.Message(pk, sender, recipients, received_date, subject, attachment_count, is_unread)

Object representation of an email.

static deserialize(msg, html=None)

Deserialize a dict of data into a Message

Parameters:
  • msg – The message as JSON
  • html – The message’s body as HTML (str)
Returns:

Message

set_body(html)

Set the message’s body

Parameters:html – the html body to set

Exceptions

class smtp4dev.smtp4dev.ApiError

An error during an API call

License

Copyright 2020 Plentific Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Indices and tables