2023-04-23 21:38:47 +00:00
|
|
|
from json import loads
|
|
|
|
from re import findall
|
|
|
|
from time import sleep
|
|
|
|
|
|
|
|
from fake_useragent import UserAgent
|
2023-04-22 09:57:45 +00:00
|
|
|
from requests import Session
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-16 16:10:37 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
class Emailnator:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.client = Session()
|
2023-04-23 21:38:47 +00:00
|
|
|
self.client.get("https://www.emailnator.com/", timeout=6)
|
2023-04-22 09:57:45 +00:00
|
|
|
self.cookies = self.client.cookies.get_dict()
|
2023-03-29 20:10:42 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
self.client.headers = {
|
2023-04-23 21:38:47 +00: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 09:57:45 +00:00
|
|
|
}
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
self.email = None
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
def get_mail(self):
|
2023-04-23 21:38:47 +00:00
|
|
|
response = self.client.post(
|
|
|
|
"https://www.emailnator.com/generate-email",
|
|
|
|
json={
|
|
|
|
"email": [
|
|
|
|
"domain",
|
|
|
|
"plusGmail",
|
|
|
|
"dotGmail",
|
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
self.email = loads(response.text)["email"][0]
|
|
|
|
return self.email
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
def get_message(self):
|
2023-04-27 01:12:33 +00:00
|
|
|
print("Waiting for message...")
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
while True:
|
|
|
|
sleep(2)
|
2023-04-29 10:20:18 +00:00
|
|
|
mail_token = self.client.post("https://www.emailnator.com/message-list", json={"email": self.email})
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
mail_token = loads(mail_token.text)["messageData"]
|
2023-04-23 21:38:47 +00:00
|
|
|
|
2023-04-22 09:57:45 +00:00
|
|
|
if len(mail_token) == 2:
|
2023-04-27 01:12:33 +00:00
|
|
|
print("Message received!")
|
2023-04-22 09:57:45 +00:00
|
|
|
print(mail_token[1]["messageID"])
|
|
|
|
break
|
|
|
|
|
2023-04-23 21:38:47 +00:00
|
|
|
mail_context = self.client.post(
|
|
|
|
"https://www.emailnator.com/message-list",
|
|
|
|
json={
|
|
|
|
"email": self.email,
|
|
|
|
"messageID": mail_token[1]["messageID"],
|
|
|
|
},
|
|
|
|
)
|
2023-04-22 09:57:45 +00:00
|
|
|
|
2023-04-23 21:38:47 +00:00
|
|
|
return mail_context.text
|
2023-03-29 20:10:42 +00:00
|
|
|
|
2023-04-23 21:38:47 +00:00
|
|
|
def get_verification_code(self):
|
2023-04-27 01:12:33 +00: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()
|