Python pull back plain text body from message from IMAP account

前端 未结 2 1476
忘掉有多难
忘掉有多难 2021-01-24 18:39

I have been working on this and am missing the mark.

I am able to connect and get the mail via imaplib.

msrv = imaplib.IMAP4(server)
msrv.login(username,         


        
2条回答
  •  太阳男子
    2021-01-24 19:40

    Here is a minimal example from the docs:

    import getpass, imaplib
    
    M = imaplib.IMAP4()
    M.login(getpass.getuser(), getpass.getpass())
    M.select()
    typ, data = M.search(None, 'ALL')
    for num in data[0].split():
        typ, data = M.fetch(num, '(RFC822)')
        print 'Message %s\n%s\n' % (num, data[0][1])
    M.close()
    M.logout()
    

    In this case, data[0][1] contains the message body.

提交回复
热议问题