Get imap or pop3 mail attachments matching an address and subject and save to file
usage: get_email.py [-h] [--quiet] [--pop3] --user USER --password PASSWORD
--server SERVER --valid VALID [VALID ...] --match MATCH
[MATCH ...] [--delete] [--ignore]
- matching valid senders 'address@domain' and
- matching subject, using a regular expression
eg. '.* attachment' and save to filename as specified in the mail. Files with the same name will be overwritten by a later mail if found.
-q/--quiet: Quiet mode
-d/--delete: Delete message after saving to file
-i/--ignore: Also delete ignored messages
python get_email.py --server mail.example.com -u user -p password123 -v 'NoReply@sample' -m '.* lims'
Info: imap login to mail.example.com as user, 5 messages
Ignoring mail from John Smith <[email protected]>. Subject "lims".
Sender match: "[email protected]".
Subject match: "Account lims was executed at 10/18/2022 4:00:07 PM".
Attachment saved as Account_lims.csv
python get_email.py --server mail.example.com -u user -p password123 -v 'john' -m 'lims'
Sender match: "John Smith <[email protected]>".
Subject match: "lims".
Attachment saved as system_lims.csv
Attachment saved as attention_contact_lims.csv
Attachment saved as location_lims.csv
Attachment saved as Account_lims.csv
Ignoring mail from [email protected] Subject "Account lims was executed at 10/18/2022 4:00:07 PM".
Ignoring mail from [email protected] Subject "attention contact lims was executed at 10/18/2022 4:10:03 PM".
Ignoring mail from [email protected] Subject "location lims was executed at 10/18/2022 4:20:00 PM".
Ignoring mail from [email protected] Subject "system lims was executed at 10/18/2022 4:30:06 PM".
To delete both invalid and downloaded messages, use both -d and -i