• 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
  • 相关阅读:
    python练习六十二:文件处理,往文件中所有添加指定的前缀
    python练习六十一:文件处理,读取文件内容
    使用广度优先搜素查找路径
    不同路径 II
    使用深度优先搜索查找路径
    不同路径
    深度优先搜索
    旋转链表
    java 迭代
    表示图的数据类型
  • 原文地址:https://www.cnblogs.com/tuwenmin/p/3335211.html
Copyright © 2020-2023  润新知