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
  • 相关阅读:
    PHP里json_encode()与json_decod()区别
    数组进行排序
    tp5利用自带上传类实现单个文件与多文件上传
    mkdir() Permission denied 报错问题
    如何快速熟悉新项目的代码?
    Tp5自定义路径写入日志
    spring解决循环依赖
    spring注解的使用
    ssm的整合
    编程知识总结
  • 原文地址:https://www.cnblogs.com/tuwenmin/p/3335211.html
Copyright © 2011-2022 走看看