# 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:
```bash
pip install tempmail-python
```
Or you can install it from source:
```bash
pip install git+https://github.com/cubicbyte/tempmail-python.git
```
## Examples
Receive a message (e.g. activation code)
```python
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
```python
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
```python
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
```python
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:
```python
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](LICENSE) file for more information.
Raw data
{
"_id": null,
"home_page": "https://github.com/cubicbyte/tempmail-python",
"name": "tempmail-python",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "disposable-email temporary-email temp-email temp-mail email mail email-generator mail-generator",
"author": "cubicbyte",
"author_email": "bmaruhnenko@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c2/9c/d8d36fe45fca4d180c7bf38c4f65567f6bdb6e7507a51b66a7e3be1360c9/tempmail-python-2.3.2.tar.gz",
"platform": null,
"description": "# Python Temp Email Library\n**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.\n\n## Installation\nYou can install tempmail-python using pip:\n```bash\npip install tempmail-python\n```\n\nOr you can install it from source:\n```bash\npip install git+https://github.com/cubicbyte/tempmail-python.git\n```\n\n## Examples\n\nReceive a message (e.g. activation code)\n```python\nfrom tempmail import EMail\n\nemail = EMail()\nprint(email.address) # qwerty123@1secmail.com\n\n# ... request some email ...\n\nmsg = email.wait_for_message()\nprint(msg.body) # Hello World!\\n\n```\n\nGet all messages in the inbox\n```python\nfrom tempmail import EMail\n\nemail = EMail('example@1secmail.com')\ninbox = email.get_inbox()\n\nfor msg_info in inbox:\n print(msg_info.subject, msg_info.message.body)\n```\n\nDownload an attachment\n```python\nfrom tempmail import EMail\n\nemail = EMail(username='example', domain='1secmail.com')\nmsg = email.wait_for_message()\n\nif msg.attachments:\n attachment = msg.attachments[0]\n data = attachment.download()\n\n # Print\n print(data) # b'Hello World!\\n'\n print(data.decode('utf-8')) # Hello World!\\n\n\n # Save to file\n with open(attachment.filename, 'wb') as f:\n f.write(data)\n```\n\nGet reddit activation code\n```python\nfrom tempmail import EMail\n\ndef reddit_filter(msg):\n return (msg.from_addr == 'noreply@reddit.com' and\n msg.subject == 'Verify your Reddit email address')\n\nemail = EMail(address='redditaccount@1secmail.com')\nmsg = email.wait_for_message(filter=reddit_filter)\n# get_activation_code(html=msg.html_body)\n```\n\nSome other features:\n```python\nfrom tempmail.providers import OneSecMail\n\nemail = OneSecMail()\n\n# request_email(email=email.address)\n\n# Speed up inbox refresh rate\nOneSecMail.inbox_update_interval = 0.1 # every 100ms\n\n# Accept only emails with a specific subject, raise error after 60 seconds\nmsg = email.wait_for_message(timeout=60, filter=lambda m: m.subject == 'Hello World!')\nprint(msg.body)\n```\n\n## License\ntempmail-python is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library for generating and managing temporary email addresses.",
"version": "2.3.2",
"project_urls": {
"Homepage": "https://github.com/cubicbyte/tempmail-python"
},
"split_keywords": [
"disposable-email",
"temporary-email",
"temp-email",
"temp-mail",
"email",
"mail",
"email-generator",
"mail-generator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bdb64db986b22000e6dcafbfb5724d8e6e45bb66b8b844e3651c144739210b0e",
"md5": "9961d72f66005e3b576d8ca5e0fc222b",
"sha256": "97befd7cd3e7356a07c74ac1f591ddf350c6e48ceb2a441e5a40a17d16febeec"
},
"downloads": -1,
"filename": "tempmail_python-2.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9961d72f66005e3b576d8ca5e0fc222b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5776,
"upload_time": "2023-11-23T09:45:58",
"upload_time_iso_8601": "2023-11-23T09:45:58.864954Z",
"url": "https://files.pythonhosted.org/packages/bd/b6/4db986b22000e6dcafbfb5724d8e6e45bb66b8b844e3651c144739210b0e/tempmail_python-2.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c29cd8d36fe45fca4d180c7bf38c4f65567f6bdb6e7507a51b66a7e3be1360c9",
"md5": "d1732f321c1a57f122007a0a4cffafc9",
"sha256": "9f4cc7e3e520f6277e6f73cf93b6de2c8f21a5fa4239dd04351c5c85dbc5b3a1"
},
"downloads": -1,
"filename": "tempmail-python-2.3.2.tar.gz",
"has_sig": false,
"md5_digest": "d1732f321c1a57f122007a0a4cffafc9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4958,
"upload_time": "2023-11-23T09:46:00",
"upload_time_iso_8601": "2023-11-23T09:46:00.466134Z",
"url": "https://files.pythonhosted.org/packages/c2/9c/d8d36fe45fca4d180c7bf38c4f65567f6bdb6e7507a51b66a7e3be1360c9/tempmail-python-2.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-23 09:46:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cubicbyte",
"github_project": "tempmail-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "tempmail-python"
}