├── .gitignore ├── CHANGES.rst ├── LICENSE ├── MANIFEST.in ├── README.rst ├── setup.py └── tempmail.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | .coverage 26 | .tox 27 | nosetests.xml 28 | 29 | # Translations 30 | *.mo 31 | 32 | # Mr Developer 33 | .mr.developer.cfg 34 | .project 35 | .pydevproject 36 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | 2 | Changes 3 | ======= 4 | 5 | 0.2 (2013-08-20) 6 | ---------------- 7 | 8 | * Improved readme 9 | * Created github page 10 | * Improved docstrings for class methods 11 | * Some minor fixes 12 | 13 | 0.1 (2013-08-18) 14 | ---------------- 15 | 16 | * Initial release 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Denis Veselov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | include CHANGES.rst 4 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | temp-mail 2 | ========= 3 | 4 | Python API Wrapper for `temp-mail.org `_ service. Temp-mail is a service which lets you use anonymous emails for free. You can view full API specification in `api2.temp-mail.org `_. 5 | 6 | Requirements 7 | ------------ 8 | 9 | `requests `_ - required. 10 | 11 | `simplejson `_ - optional, for a serious speed boost in JSON decode. 12 | 13 | Installation 14 | ------------ 15 | 16 | Installing with pip:: 17 | 18 | $ pip install temp-mail 19 | 20 | Usage 21 | ----- 22 | 23 | Get all emails from given email login and domain:: 24 | 25 | from tempmail import TempMail 26 | 27 | tm = TempMail(login='denis', domain='@gnail.pw') 28 | print tm.get_mailbox() # list of emails in denis@gnail.pw 29 | 30 | Generate email address and get emails from it:: 31 | 32 | from tempmail import TempMail 33 | 34 | tm = TempMail() 35 | email = tm.get_email_address() # v5gwnrnk7f@gnail.pw 36 | print tm.get_mailbox(email) # list of emails 37 | 38 | 39 | .. image:: https://d2weczhvl823v0.cloudfront.net/saippuakauppias/temp-mail/trend.png 40 | :alt: Bitdeli badge 41 | :target: https://bitdeli.com/free 42 | 43 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup, find_packages 3 | 4 | 5 | def read(filename): 6 | return open(os.path.join(os.path.dirname(__file__), filename)).read() 7 | 8 | 9 | setup( 10 | name='temp-mail', 11 | version='0.2', 12 | license='MIT', 13 | description='Wrapper for online service which provides ' 14 | 'temporary email address: https://temp-mail.org/', 15 | long_description=read('README.rst') + read('CHANGES.rst'), 16 | keywords='temporary temp mail email address wrapper api anon ' 17 | 'anonymous secure free disposable', 18 | url='https://github.com/saippuakauppias/temp-mail', 19 | author='Denis Veselov', 20 | author_email='progr.mail@gmail.com', 21 | include_package_data=True, 22 | packages=find_packages(), 23 | install_requires=['requests'], 24 | py_modules=['tempmail'], 25 | classifiers=[ 26 | 'Development Status :: 5 - Production/Stable', 27 | 'Intended Audience :: Developers', 28 | 'Operating System :: OS Independent', 29 | 'Programming Language :: Python', 30 | 'Programming Language :: Python :: 2.6', 31 | 'Programming Language :: Python :: 2.7', 32 | 'Topic :: Internet :: WWW/HTTP' 33 | ], 34 | ) 35 | -------------------------------------------------------------------------------- /tempmail.py: -------------------------------------------------------------------------------- 1 | import string 2 | import random 3 | from hashlib import md5 4 | 5 | import requests 6 | 7 | 8 | class TempMail(object): 9 | """ 10 | API Wrapper for service which provides temporary email address. 11 | 12 | :param login: (optional) login for email address. 13 | :param domain: (optional) domain (from current available) 14 | for email address. 15 | :param api_domain: (optional) domain for temp-mail api. 16 | Default value is ``api2.temp-mail.org``. 17 | """ 18 | 19 | def __init__(self, login=None, domain=None, api_domain='api2.temp-mail.org'): 20 | self.login = login 21 | self.domain = domain 22 | self.api_domain = api_domain 23 | 24 | def __repr__(self): 25 | return u''.format(self.get_email_address()) 26 | 27 | @property 28 | def available_domains(self): 29 | """ 30 | Return list of available domains for use in email address. 31 | """ 32 | if not hasattr(self, '_available_domains'): 33 | url = 'http://{0}/request/domains/format/json/'.format( 34 | self.api_domain) 35 | req = requests.get(url) 36 | domains = req.json() 37 | setattr(self, '_available_domains', domains) 38 | return self._available_domains 39 | 40 | def generate_login(self, min_length=6, max_length=10, digits=True): 41 | """ 42 | Generate string for email address login with defined length and 43 | alphabet. 44 | 45 | :param min_length: (optional) min login length. 46 | Default value is ``6``. 47 | :param max_length: (optional) max login length. 48 | Default value is ``10``. 49 | :param digits: (optional) use digits in login generation. 50 | Default value is ``True``. 51 | """ 52 | chars = string.ascii_lowercase 53 | if digits: 54 | chars += string.digits 55 | length = random.randint(min_length, max_length) 56 | return ''.join(random.choice(chars) for x in range(length)) 57 | 58 | def get_email_address(self): 59 | """ 60 | Return full email address from login and domain from params in class 61 | initialization or generate new. 62 | """ 63 | if self.login is None: 64 | self.login = self.generate_login() 65 | 66 | available_domains = self.available_domains 67 | if self.domain is None: 68 | self.domain = random.choice(available_domains) 69 | elif self.domain not in available_domains: 70 | raise ValueError('Domain not found in available domains!') 71 | return u'{0}{1}'.format(self.login, self.domain) 72 | 73 | def get_hash(self, email): 74 | """ 75 | Return md5 hash for given email address. 76 | 77 | :param email: email address for generate md5 hash. 78 | """ 79 | return md5(email).hexdigest() 80 | 81 | def get_mailbox(self, email=None, email_hash=None): 82 | """ 83 | Return list of emails in given email address 84 | or dict with `error` key if mail box is empty. 85 | 86 | :param email: (optional) email address. 87 | :param email_hash: (optional) md5 hash from email address. 88 | """ 89 | if email is None: 90 | email = self.get_email_address() 91 | if email_hash is None: 92 | email_hash = self.get_hash(email) 93 | 94 | url = 'http://{0}/request/mail/id/{1}/format/json/'.format( 95 | self.api_domain, email_hash) 96 | req = requests.get(url) 97 | return req.json() 98 | --------------------------------------------------------------------------------