Skip to main content

A package containing a tool to send mail and a tool to monitor a mailbox easily

Project description

doc License: GPL v3


push-pypi push-doc

maintained issues pr


ubuntu unix



linkedin website mail

A package containing a tool to send mail and a tool to monitor a mailbox easily. Supports remote directories with transparentpath.


pip install mailutility


Utils to send mails, supports attaching files. Only compatible with an sending account that does not use a double authentification method.


from mailutility import MailSender
from transparentpath import TransparentPath as Tp
some_directory_path = Tp("gs://my_bucket/some_dir")
# If the password is not provided, you will asked to provide it interactively
ms = MailSender(sender="", passwd="thepasswd")
   adresses=["", ""],
   subject=f"the mail subject",
   files=[some_directory_path / "some_file_name.pdf", some_directory_path / "some_other_file_name.csv"],


Class allowing to monitor a mailbox to save attachments to a directory using conditions on sender and subjet.

If two-factor auth is activated, you will need to provide an app password instead of your regular password. If you do not have one or do not remember it, make a new one by following the instructions here (only valid for office365 acconuts): multi-factor-authentication-end-user-app-passwords

The relevant security page to set the app passwords :

MailMonitor will use threading to allow for the monitoring of different conditions and saving to different paths.

For a basic usage (monitoring one set of conditions and saving to one location) :


from mailutility import MailMonitor
mail = MailMonitor("username")
    conditions={"subject": "test",
                "sender": ""},

To monitor several sources and save to different paths, use :

    conditions=[{"sender": "a@b.c", "subject": "g"}, {"sender": "d@e.f", "subject": "h"}],
    to_path=["/home/username/Desktop", "/home/username/Documents"],

You can decide to save to GCS by using TransparentPath:

# noinspection PyShadowingNames, PyUnresolvedReferences
from transparentpath import TransparentPath as Path
from mailutility import MailMonitor
Path.set_global_fs("gcs", bucket="my_bucket", project="my_project")
mail = MailMonitor("")
    conditions={"subject": "test",
                "sender": ""},

If conditions is an empty dict, will save attachments of all incoming mails.

Any email triggering the monitor will be marked as SEEN.

Notes and warnings:

  1. Even though multiprocessing is used, any code written after the call to mail.monitor will not be executed until the monitoring ends.

  2. The file saving system tends to see mail signature as attachments, you will have to delete the files yourself, or ignore them in your analysis.

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

mailutility-0.1.82.tar.gz (46.1 kB view hashes)

Uploaded source

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