我使用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()