File size: 1,871 Bytes
a37920b
 
 
 
 
2b30701
a37920b
c38e367
2b30701
 
 
a37920b
2b30701
1396122
2b30701
a37920b
 
 
 
 
2b30701
a37920b
2b30701
a37920b
2b30701
a37920b
 
 
 
 
 
 
 
 
 
 
2b30701
 
a37920b
2b30701
 
a37920b
2b30701
 
a37920b
 
 
 
2b30701
a37920b
2b30701
 
 
 
a37920b
 
 
 
 
 
 
2b30701
a37920b
1396122
a37920b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from json import loads
from re import findall
from time import sleep

from fake_useragent import UserAgent
from requests import Session


class Emailnator:
    def __init__(self) -> None:
        self.client = Session()
        self.client.get("https://www.emailnator.com/", timeout=6)
        self.cookies = self.client.cookies.get_dict()

        self.client.headers = {
            "authority": "www.emailnator.com",
            "origin": "https://www.emailnator.com",
            "referer": "https://www.emailnator.com/",
            "user-agent": UserAgent().random,
            "x-xsrf-token": self.client.cookies.get("XSRF-TOKEN")[:-3] + "=",
        }

        self.email = None

    def get_mail(self):
        response = self.client.post(
            "https://www.emailnator.com/generate-email",
            json={
                "email": [
                    "domain",
                    "plusGmail",
                    "dotGmail",
                ]
            },
        )

        self.email = loads(response.text)["email"][0]
        return self.email

    def get_message(self):
        print("waiting for code...")

        while True:
            sleep(2)
            mail_token = self.client.post(
                "https://www.emailnator.com/message-list", json={"email": self.email}
            )

            mail_token = loads(mail_token.text)["messageData"]

            if len(mail_token) == 2:
                print(mail_token[1]["messageID"])
                break

        mail_context = self.client.post(
            "https://www.emailnator.com/message-list",
            json={
                "email": self.email,
                "messageID": mail_token[1]["messageID"],
            },
        )

        return mail_context.text

    def get_verification_code(self):
        return findall(r';">(\d{6,7})</div>', self.get_message())[0]