• 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
  • 相关阅读:
    java基础
    C++菜鸟启动之旅--vc6.0使用教程详解
    第8章 Linux磁盘与文件系统管理
    IO(四)----对象的序列化
    IO(三)----序列流
    IO(二)----字符流
    IO(一)----字节流
    File类
    枚举类
    自动装箱和自动拆箱
  • 原文地址:https://www.cnblogs.com/tuwenmin/p/3335211.html
Copyright © 2020-2023  润新知