Skip to main content

doc License: GPL v3

Status

push-pypi push-doc

maintained issues pr

Compatibilities

ubuntu unix

python

Contact

linkedin website mail

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

Installation

pip install mailutility

MailSender

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

Usage

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="chien@chat.com", passwd="thepasswd")
ms.test_mail_server()
ms.send_mail(
   adresses=["foo@bar.com", "foo2@bar2.com"],
   subject=f"the mail subject",
   files=[some_directory_path / "some_file_name.pdf", some_directory_path / "some_other_file_name.csv"],
)

MailMonitor

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): https://docs.microsoft.com/fr-fr/azure/active-directory/user-help/ multi-factor-authentication-end-user-app-passwords

The relevant security page to set the app passwords : https://account.activedirectory.windowsazure.com/Proofup.aspx

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) :

Usage

from mailutility import MailMonitor
mail = MailMonitor("username")
mail.monitor(
    conditions={"subject": "test",
                "sender": "cottephi@gmail.com"},
    to_path="/home/username/Bureau",
    time_to_sleep=5
)

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

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

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("tomonitor@mailbox.com")
mail.monitor(
    conditions={"subject": "test",
                "sender": "chient@chat.com"},
    to_path=Path("attachment"), 
    time_to_sleep=5
)

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.

Metadata

Release files for mailutility 0.1.82

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

Source distribution (sdist)

Source distribution for mailutility 0.1.82
File Size Uploaded
mailutility-0.1.82.tar.gz 46.1 kB Details

Release files / mailutility-0.1.82.tar.gz

Download URL mailutility-0.1.82.tar.gz
Size 46.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fefde755a99edcdfb84d4e65616c2ef82d8925c850f636f5cb1e731d400fbc41
BLAKE2b-256 checksum
How to use checksums
16490328b315619e414777e198c825d793c0f66d672eb13face4a61933596d22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.1.82 This release

1 release file

0.1.81

1 release file

0.1.80

1 release file

0.1.78

1 release file

0.1.77

1 release file

0.1.76

1 release file

0.1.75

1 release file

0.1.74

1 release file

0.1.73

1 release file

0.1.71

1 release file

0.1.70

1 release file

0.1.69

1 release file

0.1.60

1 release file

0.1.57

1 release file

0.1.54

1 release file

0.1.51

1 release file

0.1.48

1 release file

0.1.46

1 release file

0.1.42

1 release file

0.1.39

1 release file

0.1.36

1 release file

0.1.32

1 release file

0.1.29

1 release file

0.1.23

1 release file

0.1.14

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

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