Created
August 7, 2024 13:32
-
-
Save motebaya/dea67fe538b42cc2e28808979d8f19ae to your computer and use it in GitHub Desktop.
Asynchronous emailnator.com api wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# emailnator.com api wrapper - 01/06/2024 | |
# @github.com/motebaya | |
from httpx import AsyncClient | |
from urllib.parse import urlparse, unquote | |
from typing import Dict, Any, Union, List | |
from colorama.ansi import Fore as col | |
import json | |
class Emailnator: | |
def __init__(self) -> None: | |
self.host = "https://www.emailnator.com" | |
self.client = AsyncClient( | |
base_url=self.host, | |
headers={ | |
"Host": urlparse(self.host).netloc, | |
"Origin": self.host, | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" | |
} | |
) | |
def getToken(self) -> str: | |
return unquote(self.client.cookies.get("XSRF-TOKEN")) | |
async def setCsrf(self) -> None: | |
print(f" [{col.BLUE}emaillnator{col.RESET}] token set..") | |
await self.client.get(f"{self.host}/") | |
async def generateEmail(self) -> Union[str, None]: | |
print(f" [{col.BLUE}emailnator{col.RESET}] generating new email..") | |
request = await self.client.post("/generate-email", data=json.dumps( | |
{"email":["plusGmail","dotGmail"]}), headers={ | |
"Content-Type": "application/json", | |
"Referer": f"{self.host}/", | |
"X-XSRF-TOKEN": self.getToken() | |
}) | |
email = request.json() | |
if (mail := email.get("email")): | |
if len(mail) != 0: | |
return mail[0] | |
return | |
return | |
async def getMessageList(self, email: str) -> Union[List[Dict[str, Any]], None]: | |
print(f" [{col.BLUE}emaillnator{col.RESET}] getting msg list from::{col.GREEN}{email}{col.RESET}") | |
request = await self.client.post("/message-list", data=json.dumps({ | |
"email": email | |
}), headers={ | |
"Content-Type":"application/json", | |
"Referer": f"{self.host}/inbox", | |
"X-XSRF-TOKEN": self.getToken() | |
}) | |
message = request.json() | |
if (msgdata := message.get("messageData")): | |
if len(msgdata) != 0: | |
return msgdata | |
return | |
return | |
async def getMessage(self, email: str, idm: str) -> str: | |
print(f" [{col.BLUE}emaillnator{col.RESET}] reading msg from::{col.GREEN}{idm}{col.RESET}..") | |
request = await self.client.post("/message-list", data=json.dumps({ | |
"email": email, | |
"messageID": idm | |
}), headers={ | |
"Content-Type": "application/json", | |
"Referer": f"{self.host}/inbox/{email}/{idm}", | |
"X-XSRF-TOKEN": self.getToken() | |
}) | |
return request.text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rules:
setCsrf()
set csrftokengenerateEmail()
get emailgetMessageList(email: generateEmail())
show all list msg from inboxgetMessage(email: generateEmail(), idm: <idMessage>)
open msg