Skip to main content

📧 Simple and intuitive, yet full featured API wrapper for www.1secmail.com, supporting both synchronous and asynchronous operations.

Project description


1secMail

An API wrapper for www.1secmail.com written in Python.

About

This is an easy to use yet full-featured Python API wrapper for www.1secmail.com ↗ using the official 1secMail API. It allows you to easily create temporary email addresses for testing, verification, or other purposes where you need a disposable email address.

Asynchronous operations are also supported!:thumbsup:

Install

To install the package, you'll need Python 3.8 or above installed on your computer. From your command line:

pip install 1secMail

Note If you're willing to install the development version, do the following:

git clone https://github.com/qvco/1secMail-Python.git

cd 1secMail-Python

pip install -r requirements.txt

pip install -e .

Usage

Generating Email Addresses

To generate a list of random email addresses, use the random_email() method:

import secmail

client = secmail.Client()

client.random_email(amount=3)
>>> ['c3fho3cry1@1secmail.net', '5qcd3d36zr@1secmail.org', 'b6fgeothtg@1secmail.net']

You can also generate a custom email address by specifying the username and domain:

Note Specifying a domain is optional!

client.custom_email(username="bobby-bob", domain="kzccv.com")
>>> 'bobby-bob@kzccv.com'

Receiving Messages

To wait until a new message is received, use the await_new_message() method:

message = client.await_new_message("bobby-bob@kzccv.com")

To check all messages received on a particular email address, use the get_inbox() method and pass the email address:

inbox = client.get_inbox("bobby-bob@kzccv.com")
for message in inbox:
    print(message.id)
    print(message.from_address)
    print(message.subject)
    print(message.date)

You can also fetch a single message using the get_message() method and passing the email address and message ID:

message = client.get_message(address="bobby-bob@kzccv.com", message_id=235200687)
print(message.id)
print(message.subject)
print(message.body)
print(message.text_body)
print(message.html_body)
print(message.attachments)
print(message.date)

Downloading an attachment

You can download an attachment from a message in the inbox of a specified email address using the download_attachment method like this:

client.download_attachment(address, message_id, attachment_filename)
>>> 'Path: (C:\Users\user\path/config/rocket.png), Size: 49071B'

Asynchronous Client

Generating Email Addresses

To generate a list of random email addresses, use the random_email() method:

import asyncio
import secmail

async def main():
    client = secmail.AsyncClient()
    email_addresses = await client.random_email(amount=3)
    print(email_addresses)

asyncio.run(main())
>>> ['c3fho3cry1@1secmail.net', '5qcd3d36zr@1secmail.org', 'b6fgeothtg@1secmail.net']

You can also generate a custom email address by specifying the username and domain:

Note Specifying a domain is optional!

await client.custom_email(username="bobby-bob", domain="kzccv.com")
>>> 'bobby-bob@kzccv.com'

Receiving Messages

To wait until a new message is received, use the await_new_message() method:

import asyncio
import secmail

async def main():
    client = secmail.AsyncClient()
    message = await client.await_new_message("bobby-bob@kzccv.com")
    print(f"{message.from_address}: {message.subject}")

asyncio.run(main())

To check all messages received on a particular email address, use the get_inbox() method and pass the email address:

import asyncio
import secmail

async def main():
    client = secmail.AsyncClient()
    inbox = await client.get_inbox("bobby-bob@kzccv.com")
    print(f"You have {len(inbox)} messages in your inbox.")

    for message in inbox:
        print(message.id)
        print(message.from_address)
        print(message.subject)
        print(message.date)

asyncio.run(main())

You can also fetch a single message using the get_message() method and passing the email address and message ID:

import asyncio
import secmail

async def main():
    client = secmail.AsyncClient()
    address = "bobby-bob@kzccv.com"
    inbox = await client.get_inbox(address)
    message_id = inbox[0].id
    message = await client.get_message(address, message_id)

    print(message.id)
    print(message.subject)
    print(message.body)
    print(message.text_body)
    print(message.html_body)
    print(message.attachments)
    print(message.date)

asyncio.run(main())

Downloading an attachment

You can download an attachment from a message in the inbox of a specified email address using the download_attachment method like this:

import asyncio
import secmail

async def main():
    client = secmail.AsyncClient()
    address = "bobby-bob@kzccv.com"
    inbox = await client.get_inbox(address)
    message_id = inbox[0].id
    message = await client.get_message(address, message_id)
    attachment_filename = message.attachments[0].filename
    await client.download_attachment(address, message_id, attachment_filename)

asyncio.run(main())

>>> 'Path: (C:\Users\user\path/config/rocket.png), Size: 49071B'

Licnese

This software is licensed under the MIT © Qvco.

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

1secMail-1.2.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

1secMail-1.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file 1secMail-1.2.0.tar.gz.

File metadata

  • Download URL: 1secMail-1.2.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for 1secMail-1.2.0.tar.gz
Algorithm Hash digest
SHA256 169955e6239aa2b3e039388dae0a4f6d26ef4f0a86806562c0b21be79d78450c
MD5 e99d7d1765c5225c9e44aac9301bf044
BLAKE2b-256 d3cb9908c2735deef9b2ddc94c64c2709a9724495da4884fe4e1954196310266

See more details on using hashes here.

File details

Details for the file 1secMail-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: 1secMail-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for 1secMail-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e2e01fd8ed95abab90de2ec5dbf8f6e0687398ba90583d01b0d39c322aa008a
MD5 264136ca4729b652fd9814d960996c63
BLAKE2b-256 93847a6bbe6c03787579920b4407f8ddb6551a948405a41362de31bce6ab237c

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