XD blog

blog page

email, gmail, imap, python


2014-01-22 Automatically saving emails on a local folder

When my student have their exams, I receive many emails with their solution attached to them. I avoid downloading them all because it is manual. However, a couple of days ago, I thought it might be useful if I write the tool which does it for me (I'm still refusing to do it manually). I ended up writing a Python module called pymmails. To get the email from my students, I just had to execute the following script:

from pyquickhelper import fLOG
from pymmails import MailBoxImap
fLOG(OutputPrint=True)
user = "your.email"
pwd = "password"
server = "imap.your_provider.ext"
box = MailBoxImap(user, pwd, server)
box.login()
box.dump_html(folder="students_exam", pattern='FROM "ensae" SINCE 1-Dec-2013')
box.logout()

All the attachments were in a single folder. I hope I'll remember my own trick next year or maybe I'll use jinja2 or even pelican to make it better.

Among others things, it was not straight forward to write this code. I had to gather some piece of information such as:


<-- -->

Xavier Dupré