Shmail / temp_mail_tm.py
Hxbzbb7272's picture
Create temp_mail_tm.py
8250ccf verified
Raw
History Blame Contribute Delete
2.29 kB
#!/usr/bin/env python3
import requests
import random
import string
BASE = "https://api.mail.tm"
VERSION = "1.0"
session = requests.Session()
email = None
password = None
def rand_str(n=10):
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=n))
def generate_email():
global email, password
print("πŸ“‘ Fetching data...")
r = session.get(f"{BASE}/domains")
domain = r.json()["hydra:member"][0]["domain"]
email = f"{rand_str()}@{domain}"
password = rand_str(12)
# create account
session.post(f"{BASE}/accounts", json={
"address": email,
"password": password
})
# login
token_res = session.post(f"{BASE}/token", json={
"address": email,
"password": password
})
token = token_res.json().get("token")
session.headers.update({"Authorization": f"Bearer {token}"})
print("\nβœ… Temporary email created!")
print(f"πŸ‘‰ Your temporary email address is:\n{email}")
def check_inbox():
if not email:
print("❌ Generate email first")
return
print("πŸ“‘ Fetching data...")
r = session.get(f"{BASE}/messages")
msgs = r.json().get("hydra:member", [])
if not msgs:
print("πŸ“­ No messages")
return
print(f"\nπŸ“¬ Inbox ({email})")
print("-" * 30)
for i, m in enumerate(msgs, 1):
print(f"{i}. {m['subject']}")
print(f" From: {m['from']['address']}")
# get full message
msg_id = m["id"]
full = session.get(f"{BASE}/messages/{msg_id}").json()
print(f" Message: {full.get('text', '')}")
print("-" * 30)
def menu():
while True:
print("\nπŸ“§ mail.tm Temporary Email Tool")
print("1. Generate a Temporary Email Address")
print("2. Check Inbox / Get Messages")
print("3. Check Version")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
generate_email()
elif choice == "2":
check_inbox()
elif choice == "3":
print(f"πŸ”§ Version: {VERSION}")
elif choice == "4":
print("πŸ‘‹ Goodbye")
break
else:
print("❌ Invalid choice")
if __name__ == "__main__":
menu()