2023-04-27 09:34:05 +00:00
|
|
|
from random import choices
|
2023-04-27 14:43:59 +00:00
|
|
|
from string import ascii_letters
|
|
|
|
|
|
|
|
from requests import Session
|
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
|
|
|
|
class Mail:
|
|
|
|
def __init__(self, proxies: dict = None) -> None:
|
|
|
|
self.client = Session()
|
|
|
|
self.client.proxies = proxies
|
|
|
|
self.client.headers = {
|
|
|
|
"host": "api.mail.tm",
|
|
|
|
"connection": "keep-alive",
|
|
|
|
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
|
|
|
|
"accept": "application/json, text/plain, */*",
|
|
|
|
"content-type": "application/json",
|
|
|
|
"sec-ch-ua-mobile": "?0",
|
|
|
|
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
|
|
|
|
"sec-ch-ua-platform": "\"macOS\"",
|
|
|
|
"origin": "https://mail.tm",
|
|
|
|
"sec-fetch-site": "same-site",
|
|
|
|
"sec-fetch-mode": "cors",
|
|
|
|
"sec-fetch-dest": "empty",
|
|
|
|
"referer": "https://mail.tm/",
|
|
|
|
"accept-encoding": "gzip, deflate, br",
|
|
|
|
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8"
|
|
|
|
}
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
def get_mail(self) -> str:
|
|
|
|
token = ''.join(choices(ascii_letters, k=14)).lower()
|
2023-04-27 14:43:59 +00:00
|
|
|
init = self.client.post("https://api.mail.tm/accounts", json={
|
|
|
|
"address": f"{token}@bugfoo.com",
|
2023-04-27 09:34:05 +00:00
|
|
|
"password": token
|
|
|
|
})
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
if init.status_code == 201:
|
2023-04-27 14:43:59 +00:00
|
|
|
resp = self.client.post("https://api.mail.tm/token", json={
|
2023-04-27 09:34:05 +00:00
|
|
|
**init.json(),
|
|
|
|
"password": token
|
|
|
|
})
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
return f"{token}@bugfoo.com"
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
else:
|
|
|
|
raise Exception("Failed to create email")
|
2023-04-27 14:43:59 +00:00
|
|
|
|
2023-04-27 09:34:05 +00:00
|
|
|
def fetch_inbox(self):
|
|
|
|
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
|
|
|
|
|
|
|
|
def get_message(self, message_id: str):
|
|
|
|
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
|
|
|
|
|
|
|
|
def get_message_content(self, message_id: str):
|
|
|
|
return self.get_message(message_id)["text"]
|