1

我正在使用 poplib 连接到 gmail 帐户,我希望它回复发送给它的电子邮件。然而,有时我的正则表达式语句会抓取不是我想要回复的随机电子邮件。

例如:

5952f967.8543630a.1c70d.283f@mx.google.com

下面的代码:

def checkEmail():

mail = poplib.POP3_SSL('pop.gmail.com')
mail.user(USER)
mail.pass_(PASS)
numEmails = len(mail.list()[1])
count = 0 

if(numEmails>=1):
    for i in range(numEmails):
        for msg in mail.retr(i+1)[1]:
            sender = re.findall(r'[\w\.-]+@[\w\.-]+',msg)
            for s in sender:
                if s and count == 0:
                    count += 1
                    replySender(s)
                    print s
            message = email.message_from_string(msg)
count = 0
mail.quit()
4

0 回答 0