2

Very simple Python script to dump all emails in an IMAP folder to files.

 1 year ago
source link: https://gist.github.com/robulouski/7442321
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Instantly share code, notes, and snippets.

Very simple Python script to dump all emails in an IMAP folder to files.

Very useful, thank you. Only had to add parentheses to print()'s for 3.4 compatibility.

Getting "ERROR: Unable to open mailbox " . Why is it unable to open mailbox?

How to check Unseen messages only

paloha

commented

Oct 1, 2020

edited

I have updated it to Python3 and extended it to support an UPLOAD mode.
Check https://gist.github.com/paloha/a5dc2843a342b1f8b814c92a098ca2a2

I have updated it to Python3 and extended it to support an UPLOAD mode.
Check https://gist.github.com/paloha/a5dc2843a342b1f8b814c92a098ca2a2

can u give me tutorial for use ur script? i got error because

@kingsalman99 what tutorial would you like to have? You just need to create a tmp folder, set your credentials at the beginning of the script and run it with python. What error did you get? Also be sure you refer to your IMAP folders correctly. I had a structure INBOX.FolderToBeDownloaded or INBOX.FolderToUpload, this might be different in your case. You should be able to list the folders with imaplib. This answer might help: https://stackoverflow.com/questions/44230855/python-imaplib-selecting-folders

solved thanks

How do you get the emails out of the folder? I can specify a folder with "M.select('folder-name')" but I don't know how to iterate over emails in that folder. Thanks very much

@julkhami - you do it with search. See line 25:

rv, data = M.search(None, "ALL")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK