Skip to main content

A basic wrapper around various temp mail sites, aiming to provide an almost identical api for every site. The main purpose of this is to provide an easy way to quickly register an account on various sites and then discard the email.

Project description

temp-mails

A basic wrapper around almost all temp mail sites on google, aiming to provide an almost identical api for every site.

The main purpose of this is to provide an easy way to use different temp mail services with almost the same python api, meaning little refactoring is needed.
If there are any issues, please send me an email (bertigert@riseup.net) or create an issue, i cant test every email for every change I or the host makes since this library supports all temp mail providers which I could find on google (see below) which work and are not captcha protected.

Installation

While every python3 version should hypothetically work, python 3.12 is best

pip install temp-mails

Requirements

pip install requests beautifulsoup4 lxml websocket-client==1.7.0

Note that you may need to uninstall all websocket packages in order for websocket-client to function properly

Usage

Create an email on the site https://10minemail.com/

from temp_mails import Tenminemail_com
from send_email import send_email_sync

# Generate a random email address
mail = Tenminemail_com()
# Get the email (e.g. example, examplehost, example@examplehost.com)
print(mail.name, mail.domain, mail.email)

# Get all emails in the inbox
print(mail.get_inbox())

# Send the email (by signing up or similar)
send_email_sync(mail.email)

# Wait for a new email for 120 seconds and get the email data.
data = mail.wait_for_new_email(delay=1.0, timeout=120) 
print(data)

# Get the content of the email, some tempmail services don't need this step
if data: # It returns None if something unexpected happens
    print(mail.get_mail_content(message_id=data["id"]))

The wrapper api for each email host is very similar, so little refactoring is needed in order to change the email host. However, the email data may change in format or similar. One email host could just return a string with the html content of the email, another one could return a dict with subject, content etc, I will probably add better support for that at some point.
Also note that only some hosts support user defined names/domains.
Also note that the built in wait_for_mail can break if there are too many emails or too many emails at once. You can implement you own custom function for that case. It works for all my use cases though (verifications etc). Many built in wait_for_new_email functions have optimizations in them, so you should use them unless absolutely necessary.
This libray is designed with minimal error handling built in. This is because if an error occurs in the library, something broke and it wouldn't work anyways, there is no way for automatic recovery since it is all based on 3rd party sites.

Some additional information

Some temp mails are really responsive, thus using wait_for_new_email in a sync program may be too slow. Because of this, for some tempmails there is a way to use threads (+3 loc):

from time import sleep
from threading import Event
from concurrent.futures import ThreadPoolExecutor

from temp_mails import Byom_de
from send_email import send_email_sync

mail = Byom_de()
print(mail.email)
  
# Set up the event which can be used by the wait_for_new_email function to signal that it's ready
is_ready_event = Event()
# Start the wait function inside of a thread
t = ThreadPoolExecutor().submit(mail.wait_for_new_email, is_ready_event=is_ready_event)

# Wait for the wait function to be ready
is_ready_event.wait()

# Send the email (by signing up or similar)
send_email_sync(mail.email)

# Get the result from the wait function
result = t.result()

print(result)

You can check if a tempmail provides this feature by checking if the wait_for_new_email function has is_ready_event as an argument. I will add this to more functions on demand.

Another way to avoid being too slow is the start_length argument in some wait_for_new_email function. Some tempmails check for a new mail by checking if the inbox changed. In order to get the start_length, the inbox is checked once. If the email is received before this call is made, the email cannot be awaited. By using start_length as an argument, you can specify the start_length of the inbox:

from temp_mails import Tempmail_id
from send_email import send_email_sync

mail = Tempmail_id()

# Get the old length of the inbox. If you are certain that this email is new, you can assume it's 0 and skip this step.
old_length = len(mail.get_inbox())

# Send the email
r = send_email_sync(mail.email)

# Wait for the mail using the old_length. Normally the old_length would be defined in this function call, after the email has been sent.
data = mail.wait_for_new_email(start_length=old_length)

print(data)

Supported Unique Sites (119) (~107 working as of 23.08.2024)

unofficial = we use no official API, because the website does not offer one (at least for free)
semi-official = website hat an official API, but we don't use it, often because it is using RapidAPI, broken or requires an API key
official = we use the websites official API (RapidAPI or not)
captcha = requires you to go onto the website and solve a captcha/verify your browser on the same IP. After that it should work for some requests/minutes. You may need to manually add a captcha response. In some cases, it just does not work anymore, I won't remove the script though as the "knowledge" could still be interesting.

In Progress

  • None

Sites which worked at some point

Websites I won't add

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

temp_mails-2.1.2.tar.gz (65.6 kB view details)

Uploaded Source

Built Distribution

temp_mails-2.1.2-py3-none-any.whl (134.5 kB view details)

Uploaded Python 3

File details

Details for the file temp_mails-2.1.2.tar.gz.

File metadata

  • Download URL: temp_mails-2.1.2.tar.gz
  • Upload date:
  • Size: 65.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for temp_mails-2.1.2.tar.gz
Algorithm Hash digest
SHA256 97d72174f245570b81e102b57b295cf82dcdc086b3bd367910ed2a1284106ac9
MD5 747ab6238e542ab8b8781059c9ffe4f1
BLAKE2b-256 f3d5428b3cfdfb38b5e72b6bcbdf3c7a6525a50a1bdff6a9561cafb40550beae

See more details on using hashes here.

File details

Details for the file temp_mails-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: temp_mails-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 134.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for temp_mails-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fae16813f2ef175f98212f66eab0e3e1537b70545c2a229de252720c4163b5f3
MD5 016501bb0673fcfd972217c253aa38d6
BLAKE2b-256 e4f87908c8afd0160983b4cb3ace73ded2d439b69d3a5acdf1f201a73eae0753

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page