tempmail-python is a Python library for generating and managing temporary email addresses using the 1secmail service. It provides functions for creating email addresses, checking for new messages, and retrieving message contents.
You can install tempmail-python using pip:
pip install tempmail-pythonOr you can install it from source:
pip install git+https://github.com/cubicbyte/tempmail-python.gitReceive a message (e.g. activation code)
fromtempmailimportEMailemail=EMail()
print(email.address) # qwerty123@1secmail.com# ... request some email ...msg=email.wait_for_message()
print(msg.body) # Hello World!\nGet all messages in the inbox
fromtempmailimportEMailemail=EMail('example@1secmail.com')
inbox=email.get_inbox()
formsg_infoininbox:
print(msg_info.subject, msg_info.message.body)Download an attachment
fromtempmailimportEMailemail=EMail(username='example', domain='1secmail.com')
msg=email.wait_for_message()
ifmsg.attachments:
attachment=msg.attachments[0]
data=attachment.download()
# Printprint(data) # b'Hello World!\n'print(data.decode('utf-8')) # Hello World!\n# Save to filewithopen(attachment.filename, 'wb') asf:
f.write(data)Get reddit activation code
fromtempmailimportEMaildefreddit_filter(msg):
return (msg.from_addr=='noreply@reddit.com'andmsg.subject=='Verify your Reddit email address')
email=EMail(address='redditaccount@1secmail.com')
msg=email.wait_for_message(filter=reddit_filter)
# get_activation_code(html=msg.html_body)Some other features:
fromtempmail.providersimportOneSecMailemail=OneSecMail()
# request_email(email=email.address)# Speed up inbox refresh rateOneSecMail.inbox_update_interval=0.1# every 100ms# Accept only emails with a specific subject, raise error after 60 secondsmsg=email.wait_for_message(timeout=60, filter=lambdam: m.subject=='Hello World!')
print(msg.body)tempmail-python is licensed under the MIT License. See the LICENSE file for more information.