zoukankan      html  css  js  c++  java
  • python imaplib snippet

    import imaplib
    
    imap_host = 'imap.gmail.com'
    imap_user = 'youremail@gmail.com'
    imap_pass = 'password'
    
    ## open a connection 
    imap = imaplib.IMAP4_SSL(imap_host)
    
    ## login
    imap.login(imap_user, imap_pass)
    
    ## get status for the mailbox (folder) INBOX
    folderStatus, UnseenInfo = imap.status('INBOX', "(UNSEEN)")
    
    print folderStatus
    
    NotReadCounter = int(UnseenInfo[0].split()[2].strip(').,]'))
    print NotReadCounter
    
    
    ## create a new folder
    status, createFolder_response = imap.create('myFolders.xyz')
    
    ## folders list
    status, folder_list = imap.list()
    
    ## list sub-folders
    status, sub_folder_list = imap.list(directory='insd')
    
    ## select a specific folder
    status, data = imap.select('INBOX')
    
    ## searching current folder using title keywords 
    status, messages = imap.search(None, '(SUBJECT "Work Report")')
     
    ## fetching message header by  using message( ID)
    status, msg_header = imap.fetch('1', '(BODY.PEEK[HEADER])')
    
    ## fetching the full message ( ID=1)
    status, AllTheMessage= imap.fetch('1', '(RFC822)')
    
    ## moving/copying messages around folders
    status, messages  = imap.copy(msg_ids, 'myFolders.xyz')
    status, messages  = imap.move(msg_ids, 'otherFolder') - See more at: http://www.codemiles.com/python-tutorials/reading-email-in-python-t10271.html#sthash.6QOePZ7p.dpuf
  • 相关阅读:
    [BZOJ 2820]YY的GCD
    [POI 2007]ZAP-Queries
    [USACO 04OPEN]MooFest
    [HAOI 2011]Problem b
    [COGS 2258][HZOI 2015]复仇的序幕曲
    [UOJ 41]【清华集训2014】矩阵变换
    [POJ 3487]The Stable Marriage Problem
    [POJ 3252]Round Numbers
    [COGS 1799][国家集训队2012]tree(伍一鸣)
    [SDOI 2011]计算器
  • 原文地址:https://www.cnblogs.com/tuwenmin/p/3335211.html
Copyright © 2011-2022 走看看