I want to check for new emails and then opening it when it arrives in my python script. I'm new to python. This would be a part of a bot that signs up and then clicks the confirmation link in the email. There is no need to check if the sender is right, because I am sure there will be no other emails coming. I know how to search for the link in the email and opening it. The problem is waiting for the email and when it arrives, continuing with the script. Thank you in advance.
This is how my code looked like before. (Without the waiting)
import poplib
import re
import webbrowser
def getmail():
M = poplib.POP3("server")
M.user("user")
M.pass_("password")
numMessages = len(M.list()[1])
whole = ""
for i in range(numMessages):
for j in M.retr(i+1)[1]:
whole += j
result = re.search("(?P<url>https?://[^\s]+)", whole).group("url")
result = result[:-1]
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
webbrowser.get(chrome_path).open(result)
I know this code is ugly and messy and probably stupid, so if you have any suggestions about that too, I would be thankfull.