pymmails documentation

Build status Build Status Windows GitHub Issues MIT License Code Health Requirements Status

Links: pypi, github, documentation, wheel, README, blog, l-issues-todolist

What is it?

The module was started to grab emails using IMAP and to store them on a local disk. I now use it to download to material sent by my students before an oral presentation. I receive many of them and it is usually annoying to download them one by one. Here is the code I use:

from pymmails import MailBoxImap, EmailMessageRenderer

user = ""
pwd = "passsword"
server = "imap.your_provider.ext"

box = MailBoxImap(user, pwd, server)
render = EmailMessageRenderer()
for mail in box.enumerate_mails_in_folder("saved", pattern="<pattern>") :
    mail.dump(render, location=temp, fLOG=fLOG)

Some examples of patterns:

pattern='FROM "xavier" SINCE 1-Feb-2013'
pattern='FROM "xavier" SINCE 1-Feb-2013 BEFORE 5-May-2013'
pattern='FROM "xavier" SINCE 1-Feb-2013 BEFORE 5-May-2013 UNANSWERED'
pattern='CC "jacques" FROM "xavier" DELETED'
pattern='TEXT "github"'
pattern='LARGER 10000 SMALLER 1000000'
pattern='SUBJECT "programmation"'
pattern='TO "student" FLAGGED'


pip install pymmails



  • download email and attchments from an server IMAP4 (gmail for example)
  • search for recent emails

By default, IMAP functionalities are not enabled on gmail (if you have a gmail account), it can be enabled from the settings page (see Enable POP and IMAP for Google Apps).