### Install required Python packages Source: https://github.com/bertigert/temp-mails/blob/master/README.md Installs the necessary Python packages for the temp-mails library, including requests, beautifulsoup4, lxml, and a specific version of websocket-client. Users might need to uninstall existing websocket packages. ```bash pip install requests beautifulsoup4 lxml websocket-client==1.7.0 ``` -------------------------------- ### Install temp-mails package Source: https://github.com/bertigert/temp-mails/blob/master/README.md Installs the temp-mails Python package using pip. It is recommended to use Python 3.12 for best compatibility. ```bash pip install temp-mails ``` -------------------------------- ### Basic Usage with Tenminemail.com Source: https://github.com/bertigert/temp-mails/blob/master/README.md Demonstrates basic usage of the temp-mails library with the Tenminemail.com provider. It shows how to create an email, retrieve inbox contents, send an email, and wait for a new email. ```python from temp_mails import Tenminemail_com from send_email import send_email_sync # Generate a random email address # It is generally recommended to let the site determine a random email address, as custom ones often require additional requests. 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"])) ``` -------------------------------- ### Using start_length for Email Waiting Source: https://github.com/bertigert/temp-mails/blob/master/README.md Demonstrates how to use the `start_length` argument in `wait_for_new_email` to specify the initial inbox length, useful when an email might be received before the waiting function is called. ```python 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) ``` -------------------------------- ### Asynchronous Email Waiting with Threading Source: https://github.com/bertigert/temp-mails/blob/master/README.md Shows how to use threading with the temp-mails library for asynchronous email waiting, preventing the main program from blocking. It utilizes an Event object to signal readiness. ```python 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) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.