Gmail Inbox.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Web-Scraping-and-Python-Codes 作者: dushyantRathore 项目源码 文件源码
def readmail():
    username = raw_input("Enter username : ")
    password = raw_input("Enter password : ")

    mail = imaplib.IMAP4_SSL(smtp_server)

    mail.login(username, password)
    mail.select('inbox')

    type, data = mail.search(None, 'ALL')
    mail_ids = data[0]
    id_list = mail_ids.split()

    first_id = int(id_list[0])
    last_id = int(id_list[-1])

    # print first_id
    # print last_id

    for i in range(last_id, first_id, -1):
        typ, data = mail.fetch(i, '(RFC822)')

        for response in data:
            if isinstance(response, tuple):
                msg = email.message_from_string(response[1])
                email_subject = msg['subject']
                email_from = msg['from']
                print 'From : ' + email_from + '\n'
                print 'Subject : ' + email_subject + '\n'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号