├── .gitignore ├── CHANGES.rst ├── LICENSE ├── MANIFEST.in ├── README.rst ├── setup.cfg ├── setup.py └── tempmail2.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 | .pypirc 37 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | 2 | Changes 3 | ======= 4 | 5 | 1.0.1 (2018-05-26) 6 | ---------------- 7 | 8 | * Improved readme 9 | * Created github page 10 | * Improved docstrings for class methods 11 | * Some minor fixes 12 | 13 | 1.0.0 (2018-05-25) 14 | ---------------- 15 | 16 | * Initial release 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Oyetoke Toby 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 | Tempmail2 2 | ========= 3 | 4 | Python API Wrapper version 2 for `temp-mail.org `_ service. Temp-mail.org is a service which lets you use anonymous emails for free. You can view full API specification in `api.temp-mail.org `_. 5 | 6 | Requirements 7 | ------------ 8 | 9 | `requests `_ - required. 10 | 11 | You can install it through :: 12 | 13 | $ pip install requests 14 | 15 | Installation 16 | ------------ 17 | 18 | Installing with pip:: 19 | 20 | $ pip install tempMail2 21 | 22 | Usage 23 | ----- 24 | 25 | Before you can use this, you need to get api key from https://rapidapi.com/Privatix/api/temp-mail. 26 | 27 | So create an account on Mashape and get the Mashape Api Key 28 | 29 | Get all emails from given email login and domain:: 30 | 31 | from tempMail2 import TempMail 32 | 33 | tm = TempMail(api_key='apikey', login='denis', domain='@gnail.pw') 34 | print tm.get_mailbox() # list of emails in denis@gnail.pw 35 | 36 | Generate email address and get emails from it:: 37 | 38 | from tempMail2 import TempMail 39 | 40 | tm = TempMail(api_key='apikey') 41 | email = tm.get_email_address() # v5gwnrnk7f@gnail.pw 42 | print tm.get_mailbox(email) # list of emails 43 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.rst -------------------------------------------------------------------------------- /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 | long_description = read('README.rst') 10 | 11 | 12 | setup( 13 | name='tempMail2', 14 | version='1.0.3', 15 | license='MIT', 16 | description='Python wrapper for online service which provides ' 17 | 'temporary email address: https://temp-mail.org/ V2', 18 | long_description= long_description, 19 | keywords='temporary temp mail email address wrapper api anon ' 20 | 'anonymous secure free disposable', 21 | url='https://github.com/CITGuru/tempmail', 22 | author='Oyetoke Toby', 23 | author_email='oyetoketoby80@gmail.com', 24 | include_package_data=True, 25 | packages=find_packages(), 26 | install_requires=['requests'], 27 | download_url='https://github.com/CITGuru/tempmail/archive/1.0.0.tar.gz', 28 | py_modules=['tempMail2'], 29 | classifiers=[ 30 | 'Development Status :: 5 - Production/Stable', 31 | 'Intended Audience :: Developers', 32 | 'Operating System :: OS Independent', 33 | 'Programming Language :: Python', 34 | 'Programming Language :: Python :: 2.6', 35 | 'Programming Language :: Python :: 2.7', 36 | 'Programming Language :: Python :: 3.6', 37 | 'Topic :: Internet :: WWW/HTTP' 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /tempmail2.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 ``privatix-temp-mail-v1.p.mashape.com``. 17 | """ 18 | 19 | def __init__(self, api_key, login=None, domain=None, api_domain='privatix-temp-mail-v1.p.rapidapi.com'): 20 | self.login = login 21 | self.domain = domain 22 | self.api_domain = api_domain 23 | self.api_key = api_key 24 | 25 | def __repr__(self): 26 | return u''.format(self.get_email_address()) 27 | 28 | @property 29 | def available_domains(self): 30 | """ 31 | Return list of available domains for use in email address. 32 | """ 33 | if not hasattr(self, '_available_domains'): 34 | url = 'https://{0}/request/domains/format/json/'.format( 35 | self.api_domain) 36 | req = requests.get(url, headers={ 37 | 'x-rapidapi-host': self.domain, 38 | 'x-rapidapi-key': self.api_key 39 | }) 40 | domains = req.json() 41 | setattr(self, '_available_domains', domains) 42 | return self._available_domains 43 | 44 | def generate_login(self, min_length=6, max_length=10, digits=True): 45 | """ 46 | Generate string for email address login with defined length and 47 | alphabet. 48 | 49 | :param min_length: (optional) min login length. 50 | Default value is ``6``. 51 | :param max_length: (optional) max login length. 52 | Default value is ``10``. 53 | :param digits: (optional) use digits in login generation. 54 | Default value is ``True``. 55 | """ 56 | chars = string.ascii_lowercase 57 | if digits: 58 | chars += string.digits 59 | length = random.randint(min_length, max_length) 60 | return ''.join(random.choice(chars) for x in range(length)) 61 | 62 | def get_email_address(self): 63 | """ 64 | Return full email address from login and domain from params in class 65 | initialization or generate new. 66 | """ 67 | if self.login is None: 68 | self.login = self.generate_login() 69 | 70 | available_domains = self.available_domains 71 | if self.domain is None: 72 | self.domain = random.choice(available_domains) 73 | elif self.domain not in available_domains: 74 | raise ValueError('Domain not found in available domains!') 75 | return u'{0}{1}'.format(self.login, self.domain) 76 | 77 | def get_hash(self, email): 78 | """ 79 | Return md5 hash for given email address. 80 | 81 | :param email: email address for generate md5 hash. 82 | """ 83 | return md5(email.encode('utf-8')).hexdigest() 84 | 85 | def get_mailbox(self, email=None, email_hash=None): 86 | """ 87 | Return list of emails in given email address 88 | or dict with `error` key if mail box is empty. 89 | 90 | :param email: (optional) email address. 91 | :param email_hash: (optional) md5 hash from email address. 92 | """ 93 | if email is None: 94 | email = self.get_email_address() 95 | if email_hash is None: 96 | email_hash = self.get_hash(email.encode('utf-8')) 97 | 98 | url = 'https://{0}/request/mail/id/{1}/format/json/'.format( 99 | self.api_domain, email_hash) 100 | req = requests.get(url, headers={ 101 | "X-Mashape-Key": self.api_key, 102 | "Accept": "application/json" 103 | }) 104 | return req.json() 105 | 106 | def delete_email(self, email, email_hash=None): 107 | """ 108 | Delete a given email in a given email address 109 | 110 | :param email: (optional) email address. 111 | :param email_hash: (optional) md5 hash from email address. 112 | """ 113 | if email_hash is None: 114 | email_hash = self.get_hash(email.encode('utf-8')) 115 | 116 | url = 'https://{0}/request/delete/id/{1}/format/json/'.format( 117 | self.api_domain, email_hash) 118 | 119 | req = requests.get(url, headers={ 120 | "X-Mashape-Key": self.api_key, 121 | "Accept": "application/json" 122 | }) 123 | return req.json() 124 | 125 | def get_attachments(self, email, email_hash=None): 126 | """ 127 | Get attachments of a given email in a given email address 128 | 129 | :param email: (optional) email address. 130 | :param email_hash: (optional) md5 hash from email address. 131 | """ 132 | if email_hash is None: 133 | email_hash = self.get_hash(email.encode('utf-8')) 134 | 135 | url = 'https://{0}/request/attachments/id/{1}/format/json/'.format( 136 | self.api_domain, email_hash) 137 | 138 | req = requests.get(url, headers={ 139 | "X-Mashape-Key": self.api_key, 140 | "Accept": "application/json" 141 | }) 142 | return req.json() 143 | 144 | def get_message(self, email, email_hash=None): 145 | """ 146 | Get a given email in a given email address 147 | 148 | :param email: (optional) email address. 149 | :param email_hash: (optional) md5 hash from email address. 150 | """ 151 | if email_hash is None: 152 | email_hash = self.get_hash(email.encode('utf-8')) 153 | 154 | url = 'https://{0}/request/one_mail/id/{1}/format/json/'.format( 155 | self.api_domain, email_hash) 156 | 157 | req = requests.get(url, headers={ 158 | "X-Mashape-Key": self.api_key, 159 | "Accept": "application/json" 160 | }) 161 | return req.json() 162 | 163 | 164 | def source_message(self, email, email_hash=None): 165 | """ 166 | Source a given email in a given email address 167 | 168 | :param email: (optional) email address. 169 | :param email_hash: (optional) md5 hash from email address. 170 | """ 171 | if email_hash is None: 172 | email_hash = self.get_hash(email.encode('utf-8')) 173 | 174 | url = 'https://{0}/request/source/id/{1}/format/json/'.format( 175 | self.api_domain, email_hash) 176 | 177 | req = requests.get(url, headers={ 178 | "X-Mashape-Key": self.api_key, 179 | "Accept": "application/json" 180 | }) 181 | return req.json() 182 | --------------------------------------------------------------------------------