Move an email in GMail with Python and imaplib
I want to be able to move an email in GMail from the inbox to another folder using Python. I am using imaplib and can't figure out how to do it. There is no explicit move command for IMAP. You will have to execute a COPY followed by a STORE (with suitable flag to indicate deletion) and finally expunge . The example given below worked for moving messages from one label to the other. You'll probably want to add more error checking though. import imaplib, getpass, re pattern_uid = re.compile('\d+ \(UID (?P<uid>\d+)\)') def connect(email): imap = imaplib.IMAP4_SSL("imap.gmail.com") password =