Skip to main content

Python library for generating and managing temporary email addresses.

Project description

Python Temp Email Library

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.

Installation

You can install tempmail-python using pip:

pip install tempmail-python

Or you can install it from source:

pip install git+https://github.com/cubicbyte/tempmail-python.git

Examples

Receive a message (e.g. activation code)

from tempmail import EMail

email = EMail()
print(email.address)  # qwerty123@1secmail.com

# ... request some email ...

msg = email.wait_for_message()
print(msg.body)  # Hello World!\n

Get all messages in the inbox

from tempmail import EMail

email = EMail('example@1secmail.com')
inbox = email.get_inbox()

for msg_info in inbox:
    print(msg_info.subject, msg_info.message.body)

Download an attachment

from tempmail import EMail

email = EMail(username='example', domain='1secmail.com')
msg = email.wait_for_message()

if msg.attachments:
    attachment = msg.attachments[0]
    data = attachment.download()

    # Print
    print(data)  # b'Hello World!\n'
    print(data.decode('utf-8'))  # Hello World!\n

    # Save to file
    with open(attachment.filename, 'wb') as f:
        f.write(data)

Get reddit activation code

from tempmail import EMail

def reddit_filter(msg):
    return (msg.from_addr == 'noreply@reddit.com' and
            msg.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:

from tempmail.providers import OneSecMail

email = OneSecMail()

# request_email(email=email.address)

# Speed up inbox refresh rate
OneSecMail.inbox_update_interval = 0.1  # every 100ms

# Accept only emails with a specific subject, raise error after 60 seconds
msg = email.wait_for_message(timeout=60, filter=lambda m: m.subject == 'Hello World!')
print(msg.body)

License

tempmail-python is licensed under the MIT License. See the LICENSE file for more information.

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

tempmail-python-2.3.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

tempmail_python-2.3.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file tempmail-python-2.3.2.tar.gz.

File metadata

  • Download URL: tempmail-python-2.3.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for tempmail-python-2.3.2.tar.gz
Algorithm Hash digest
SHA256 9f4cc7e3e520f6277e6f73cf93b6de2c8f21a5fa4239dd04351c5c85dbc5b3a1
MD5 d1732f321c1a57f122007a0a4cffafc9
BLAKE2b-256 c29cd8d36fe45fca4d180c7bf38c4f65567f6bdb6e7507a51b66a7e3be1360c9

See more details on using hashes here.

File details

Details for the file tempmail_python-2.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tempmail_python-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 97befd7cd3e7356a07c74ac1f591ddf350c6e48ceb2a441e5a40a17d16febeec
MD5 9961d72f66005e3b576d8ca5e0fc222b
BLAKE2b-256 bdb64db986b22000e6dcafbfb5724d8e6e45bb66b8b844e3651c144739210b0e

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