1

我正在使用此代码以 10 秒的延迟检查新邮件。

import poplib
from email import parser
import time

def seeit(): 
    pop_conn = poplib.POP3_SSL('pop.gmail.com')
    pop_conn.user('xxx')
    pop_conn.pass_('xx')
    #Get messages from server:
    messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
    # Concat message pieces:a
    messages = ["\n".join(mssg[1]) for mssg in messages]
    #Parse message intom an email object:
    messages = [parser.Parser().parsestr(mssg) for mssg in messages]
    for message in messages:
        print message['subject']
    pop_conn.quit()


starttime=time.time()

while True:
    k=10.0
    print "tick"
    seeit()
    time.sleep(k - ((time.time() - starttime) % k))

如何检索没有标题的电子邮件正文?

4

1 回答 1

0

get_payload()email包中查看方法method。

从服务器收到消息后试试这个:

import email

...
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
...

for i in messages:
    mssg = email.message_from_string(i)
    print(mssg.get_payload())
于 2016-10-28T09:18:35.747 回答