Skip to main content

MuMailer

Travis CI Build Status CircleCI Build Status PyPI - Version PyPI - Python Version

Description: Simple mailer agent using SMTP

Copyright: 2021-2023 Fabio Castelli (Muflone) muflone@muflone.com

License: GPL-3+

Source code: https://github.com/muflone/mumailer

Documentation: http://www.muflone.com/mumailer/

Description

MuMailer is a simple mail transfer agent (MTA) to send email messages from Python or from command line arguments, using multiple profiles to configure arguments.

Please see below and the samples folder for some usage examples.

System Requirements

Basic usage

To use MuMailer from Python you have to instance a Connection and a Message objects and then execute the send method on the connection object passing the message object.

The Connection object refers to the SMTP server connection and it will require the SMTP server data (server, port, username, password, encryption).

The Message object will contain the information needed to send a single message (sender, recipients, subject, body, attachments).

For sender, reply-to, to, cc and bcc arguments you need to pass some Recipient objects with an email address and optionally a name (pass None if you don't want to specify the recipient name).

See the following example:

from mumailer import Connection, Message, Recipient

message = Message(sender=Recipient('Muflone', 'muflone@example.com'),
                  to=[Recipient('Foo', 'foo@example.com')],
                  cc=[Recipient('Bar', 'bar@example.com')],
                  subject='Test e-mail',
                  body='<html><body><h1>Hello world!</h1></body></html>',
                  use_html=True)
connection = Connection(server='localhost',
                        port=587,
                        username='<username>',
                        password='<smtp password>')
connection.connect()
connection.send(message)
connection.disconnect()

The previous code will prepare a message from Muflone and will send the message to Foo, adding Bar to the CC (carbon copy) list, using the subject Test e-mail with the HTML body Hello world!.

The SMTP connection will be established to the localhost server on the TCP port 587 (the server must be running) using username and password authentication. The SMTP data will be encrypted using the TLS protocol.

Adding attachments

A Message object can have one or more attachments being sent along with the message body.

To add an attachment to the Message object you have to instance an Attachment object from which you can set its content (as binary data) or load it from a file.

The class method load_filename will return an Attachment object with the file content.

from mumailer import Attachment

pdf_attachment = Attachment.load_filename(filename='myfile.pdf',
                                          content_type='application/pdf')
message.add_attachment(pdf_attachment)

txt_attachment = Attachment.load_filename(filename='document.txt',
                                          content_type='text/plain')
message.add_attachment(txt_attachment)

Adding custom headers

Custom headers can be added to the message by passing one or more Header objects to the headers argument or by adding each header to the headers list.

from mumailer import Header

header = Header(name='X-Mailer',
                value='MuMailer')
message.add_header(header)

header = Header.parse(header='X-Spam=0')
message.add_header(header)

SMTP Profiles

The SMTP settings can also be got from a profile file like the following:

SMTP:
  SERVER: <SMTP server>
  PORT: 465
  USERNAME: <username>
  PASSWORD: <password>
  TIMEOUT: 30
  ENCRYPTION: TLSv1_2
  CIPHERS:

And instance the ProfileSmtp object:

from mumailer import Connection, ProfileSmtp

profile_smtp = ProfileSmtp(filename='profile-smtp.yaml')

connection = Connection(server=profile_smtp.server,
                        port=profile_smtp.port,
                        username=profile_smtp.username,
                        password=profile_smtp.password)

Message Profiles

Message profiles files can be used to set up the options for the message to be sent, saving in a profile file the sender, the recipients, subject, attachments list and others options.

MESSAGE:
  SENDER: Muflone muflone@example.com
  TO:
    - Foo foo@example.com
  CC:
    - Bar bar@example.com
  SUBJECT: Test e-mail
  BODY: <html><body><h1>Hello world!</h1></body></html>
  HTML: true
  ATTACHMENTS:
    - README.md
    - LICENSE
  CONTENT_TYPES:
    - text/plain
    - application/octet-stream
- HEADERS:
    - X-Mailer=MuMailer
    - X-MuMailer-Profile=message.yaml

And instance the ProfileMessage object:

from mumailer import Header, Message, ProfileMessage, Recipient

profile_message = ProfileMessage(filename='profile-message.yaml')

message = Message(sender=Recipient.parse(profile_message.sender),
                  reply_to=Recipient.parse(profile_message.reply_to),
                  to=Recipient.parse_as_list(profile_message.to),
                  cc=Recipient.parse_as_list(profile_message.cc),
                  bcc=Recipient.parse_as_list(profile_message.bcc),
                  subject=profile_message.subject,
                  body=profile_message.body,
                  use_html=profile_message.use_html,
                  headers=Header.parse_as_list(profile_message.headers))

Release files for MuMailer 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MuMailer 0.5.0
File Size Uploaded
MuMailer-0.5.0.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MuMailer 0.5.0
File Interpreter ABI Platform
MuMailer-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.7 kB

Release files / MuMailer-0.5.0.tar.gz

Download URL MuMailer-0.5.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cc1267d4c44c2ffaa777531f840332d3a62e210c4e9f10641af61fbd61ac83e0
BLAKE2b-256 checksum
How to use checksums
ddd3950ce77b691141d715bd0ab85537853404212f3665a8d2da79e5e49e4d13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / MuMailer-0.5.0-py3-none-any.whl

Download URL MuMailer-0.5.0-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c26d332dd3a052024f65290d9c736ded1e288cd65aa091ada06cfa8927692a7
BLAKE2b-256 checksum
How to use checksums
0ee529cbbb4a80ea80efc6d993e5939508e5651649e2ace74e6b312fec641cf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page