Skip to content

Instantly share code, notes, and snippets.

@barik
Created December 1, 2015 22:19
Show Gist options
  • Save barik/3b36a54e9d0b27151f23 to your computer and use it in GitHub Desktop.
Save barik/3b36a54e9d0b27151f23 to your computer and use it in GitHub Desktop.
import imaplib
HOST = "mail.messagingengine.com"
USER = "[email protected]"
PASSWORD = "password"
BATCH_FOLDER = "INBOX.Batch"
INBOX_FOLDER = "INBOX"
def batch_mail():
server = imaplib.IMAP4_SSL(HOST)
server.login(USER, PASSWORD)
server.select(BATCH_FOLDER)
typ, [msg_uids] = server.uid("SEARCH", "ALL")
msg_uids = ",".join(msg_uids.split(" "))
if msg_uids:
server.uid("COPY", msg_uids, INBOX_FOLDER)
server.uid("STORE", msg_uids, "+FLAGS.SILENT", r"(\Deleted)")
server.uid("EXPUNGE", msg_uids)
return msg_uids
# noinspection PyUnusedLocal
def lambda_handler(event, context):
return batch_mail()
if __name__ == '__main__':
batch_mail()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment