Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29905

How to check for a confirmation email and then reading it in python

$
0
0

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.


Viewing all articles
Browse latest Browse all 29905

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>