Skip to main content

The unofficial Python client for the 1secmail API.

Project description

                                                   _ _
    ___  _ __   ___  ___  ___  ___ _ __ ___   __ _(_) |
   / _ \| '_ \ / _ \/ __|/ _ \/ __| '_ ` _ \ / _` | | |
  | (_) | | | |  __/\__ \  __/ (__| | | | | | (_| | | |
   \___/|_| |_|\___||___/\___|\___|_| |_| |_|\__,_|_|_|

onesecmail

The unofficial Python client for the 1secmail API.

Installation

Use the package manager pip to install onesecmail:

pip install onesecmail

Usage

Initialize a OneSecMail object using one of the class methods:

>>> from onesecmail import OneSecMail
>>> # Uses 1secmail's genRandomMailbox action to get a random adress:
>>> mailbox = OneSecMail.get_random_mailbox()
>>> print(mailbox)
<OneSecMail [p8qhrjor@wwjmp.com]>
>>> # Generates a random address using uuid.uuid4():
>>> mailbox = OneSecMail.generate_random_mailbox()
>>> print(mailbox)
<OneSecMail [c05a619fe9a544dab818bde19a74c714@1secmail.net]>
>>> # Creates a mailbox using a pre-determined address:
>>> mailbox = OneSecMail.from_address("c05a619fe9a544dab818bde19a74c714@1secmail.net")
>>> print(mailbox)
<OneSecMail [c05a619fe9a544dab818bde19a74c714@1secmail.net]>

To retrieve a specific email message, you can use the methods OneSecMail.get_message() or OneSecMail.get_message_as_dict():

>>> message = mailbox.get_message(212959953)
>>> print(message)
<EmailMessage; from='contact@yyyyyyyan.tech', subject='Hello!', date='2021-06-25 23:49:12+02:00'>
>>> message.body
'Hi\n'
>>> message_data = mailbox.get_message_as_dict(212959953)
>>> print(message_data)
{'id': 212959953,
 'from': 'contact@yyyyyyyan.tech',
 'subject': 'Hello!',
 'date': '2021-06-25 23:49:12',
 'attachments': [],
 'body': 'Hi!\n',
 'textBody': 'Hi!\n',
 'htmlBody': '',
 'to': '101c71a3206c42668ca7bda6fe225138@1secmail.com'}

To get all messages of a mailbox, use the OneSecMail.get_messages() method:

>>> messages = mailbox.get_messages()
>>> messages
[<EmailMessage; from='contact@yyyyyyyan.tech', subject='Random Email', date='2021-06-28 00:03:27+02:00'>,
 <EmailMessage; from='contact@yyyyyyyan.tech', subject='First Email', date='2021-06-28 01:06:27+02:00'>,
 <EmailMessage; from='yan@orestes.tech', subject='Second Email', date='2021-06-28 01:06:51+02:00'>]

You can also use the get_messages() method to search for email messages, by using validator functions/classes:

>>> from onesecmail.validators import FromAddressValidator
>>> from_validator = FromAddressValidator("contact@yyyyyyyan.tech")
>>> mailbox.get_messages(validators=[from_validator])
[<EmailMessage; from='contact@yyyyyyyan.tech', subject='Random Email', date='2021-06-28 00:03:27+02:00'>,
 <EmailMessage; from='contact@yyyyyyyan.tech', subject='First Email', date='2021-06-28 01:06:27+02:00'>]
>>> from onesecmail.validators import DateRangeValidator
>>> from datetime import datetime
>>> date_validator = DateRangeValidator(min_date=datetime.strptime("2021-06-28 01+02:00", "%Y-%m-%d %H%z"))
>>> mailbox.get_messages(validators=[from_validator, date_validator])
[<EmailMessage; from='contact@yyyyyyyan.tech', subject='First Email', date='2021-06-28 01:06:27+02:00'>]]
>>> from onesecmail.validators import SubjectValidator
>>> mailbox.get_messages(validators=[SubjectValidator("(First|Second) Email")])
[<EmailMessage; from='contact@yyyyyyyan.tech', subject='First Email', date='2021-06-28 01:06:27+02:00'>,
 <EmailMessage; from='yan@orestes.tech', subject='Second Email', date='2021-06-28 01:06:51+02:00'>]]

To download an attachment, use either the download_attachment() method available on both OneSecMail and EmailMessage classes:

>>> message = mailbox.get_message(213684185)
>>> message.attachments
[{'filename': 'attachment.c', 'contentType': 'text/x-csrc', 'size': 2636}]
# These do the same:
>>> message.download_attachment("attachment.c", "local-file.c")
>>> mailbox.download_attachment(213684185, "attachment.c", "local-file.c")

Contributing

Pull Requests are welcome, whether it's regarding features, tests or documentation.

Just make sure you install the pre-commit hooks in your cloned repo before commiting any changes:

git clone https://github.com/yyyyyyyan/onesecmail.git
cd onesecmail
pip install -r requirements_dev.txt
pre-commit install

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

onesecmail-0.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

onesecmail-0.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file onesecmail-0.0.1.tar.gz.

File metadata

  • Download URL: onesecmail-0.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for onesecmail-0.0.1.tar.gz
Algorithm Hash digest
SHA256 714f6807ee5a92a52b25abde2d44d53ba368f98cb0ef26e41bee3e2047c71585
MD5 069258f3c28094e53403b904485fbcbb
BLAKE2b-256 8305e65ad98cb80e5b0249acc08e90a997c6e80b2c7b41316d289495e477d319

See more details on using hashes here.

File details

Details for the file onesecmail-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: onesecmail-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for onesecmail-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b7d5afd2cd5cd0eb92b4c73ef8714d38f91405576b7811da32dd2dbee671d36
MD5 913b97aa700ca0603e82fd030b1e0b54
BLAKE2b-256 48f7ddc03116115b69ca8d2c3163f6a172784d511cee3d5bf13c3fdda74aaf13

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