2023-04-24 06:38:47 +09:00
|
|
|
from json import loads
|
|
|
|
from re import findall
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
from fake_useragent import UserAgent
|
2023-04-22 18:57:45 +09:00
|
|
|
from requests import Session
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-17 01:10:37 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
class Emailnator:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.client = Session()
|
2023-04-24 06:38:47 +09:00
|
|
|
self.client.get("https://www.emailnator.com/", timeout=6)
|
2023-04-22 18:57:45 +09:00
|
|
|
self.cookies = self.client.cookies.get_dict()
|
2023-03-30 05:10:42 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
self.client.headers = {
|
2023-04-24 06:38:47 +09:00
|
|
|
"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] + "=",
|
2023-04-22 18:57:45 +09:00
|
|
|
}
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
self.email = None
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
def get_mail(self):
|
2023-04-24 06:38:47 +09:00
|
|
|
response = self.client.post(
|
|
|
|
"https://www.emailnator.com/generate-email",
|
|
|
|
json={
|
|
|
|
"email": [
|
|
|
|
"domain",
|
|
|
|
"plusGmail",
|
|
|
|
"dotGmail",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
self.email = loads(response.text)["email"][0]
|
|
|
|
return self.email
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
def get_message(self):
|
2023-04-27 10:12:33 +09:00
|
|
|
print("Waiting for message...")
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
while True:
|
|
|
|
sleep(2)
|
2023-04-29 19:20:18 +09:00
|
|
|
mail_token = self.client.post("https://www.emailnator.com/message-list", json={"email": self.email})
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
mail_token = loads(mail_token.text)["messageData"]
|
2023-04-24 06:38:47 +09:00
|
|
|
|
2023-04-22 18:57:45 +09:00
|
|
|
if len(mail_token) == 2:
|
2023-04-27 10:12:33 +09:00
|
|
|
print("Message received!")
|
2023-04-22 18:57:45 +09:00
|
|
|
print(mail_token[1]["messageID"])
|
|
|
|
break
|
|
|
|
|
2023-04-24 06:38:47 +09:00
|
|
|
mail_context = self.client.post(
|
|
|
|
"https://www.emailnator.com/message-list",
|
|
|
|
json={
|
|
|
|
"email": self.email,
|
|
|
|
"messageID": mail_token[1]["messageID"],
|
|
|
|
},
|
|
|
|
)
|
2023-04-22 18:57:45 +09:00
|
|
|
|
2023-04-24 06:38:47 +09:00
|
|
|
return mail_context.text
|
2023-03-30 05:10:42 +09:00
|
|
|
|
2023-04-24 06:38:47 +09:00
|
|
|
def get_verification_code(self):
|
2023-04-27 10:12:33 +09:00
|
|
|
message = self.get_message()
|
|
|
|
code = findall(r';">(\d{6,7})</div>', message)[0]
|
|
|
|
print(f"Verification code: {code}")
|
|
|
|
return code
|
|
|
|
|
|
|
|
def clear_inbox(self):
|
|
|
|
print("Clearing inbox...")
|
|
|
|
self.client.post(
|
|
|
|
"https://www.emailnator.com/delete-all",
|
|
|
|
json={"email": self.email},
|
|
|
|
)
|
|
|
|
print("Inbox cleared!")
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
if self.email:
|
|
|
|
self.clear_inbox()
|