mails.py 文件源码

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

项目:Automation-Bots 作者: ab-anand 项目源码 文件源码
def main():
    global i
    clear()
    mail = imaplib.IMAP4_SSL(SMTP_SERVER)
    mail.login(FROM_EMAIL, FROM_PWD)
    mail.list()
    mail.select('inbox')
    inp = 'n'


    while(inp!='q'):
        print('Fetching mails. Please wait...')
        if inp == 'n':
            i += 1
        elif inp == 'p' and i != 1:
            i -= 1
        else:
            print('Please enter valid input.')
        result, data = mail.uid('search', None, "ALL") # search and return uids instead
        latest_email_uid = data[0].split()[-i] # fetch mails 
        result, data = mail.uid('fetch', latest_email_uid, '(RFC822)')
        raw_email = data[0][1]
        email_message = email.message_from_string(raw_email)

        clear() # clear screen and print mail
        print 'To:', email_message['To']
        print 'Sent from:', email_message['From']
        print 'Date:', email_message['Date']
        print 'Subject:', email_message['Subject']
        print '*'*30, 'MESSAGE', '*'*30
        maintype = email_message.get_content_maintype()
        #print maintype

        if maintype == 'multipart': # get the body of the mail
            print email_message.get_payload()[0].get_payload() # to get the plain text only
        elif maintype == 'text':
            line = email_message.get_payload()[ 0 ]
            print line
        print '*'*69
        welcome()
        inp = raw_input('>> Enter your choice: ').lower()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号