-
Notifications
You must be signed in to change notification settings - Fork 8
/
tempmail.py
36 lines (28 loc) · 1.22 KB
/
tempmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import html2text
def generate():
email_addres = requests.get(
"https://www.1secmail.com/api/v1/?action=genRandomMailbox&count=1", timeout=6).json()[0]
return email_addres
def refresh(username, domain):
response = requests.get(
f"https://www.1secmail.com/api/v1/?action=getMessages&login={username}&domain={domain}", timeout=6).json()
# if email have message
if response:
files = []
# last message id
email_id = response[0]["id"]
# get message info
response_msg = requests.get(
f"https://www.1secmail.com/api/v1/?action=readMessage&login={username}&domain={domain}&id={email_id}", timeout=6).json()
email_from = response_msg["from"]
email_subject = response_msg["subject"]
email_date = response_msg["date"]
email_html = response_msg["htmlBody"]
email_text = html2text.html2text(email_html)
attachments = response_msg["attachments"]
# if message have attachments
if attachments:
files = [attachment["filename"] for attachment in attachments]
return [email_id, email_from, email_subject, email_date, email_text, files]
return "No Messages Were Received.."