I'm using poplib to connect to a gmail account and I want it to reply to emails that are sent to it. However sometimes my regular expression's statement grabs random emails that aren't the one I wanted to reply to.
For example:
5952f967.8543630a.1c70d.283f@mx.google.com
Code below:
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()