Skip to content

Commit

Permalink
Added support temp-mail.org
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Pitkov committed Mar 11, 2023
1 parent 75cfe5e commit e029730
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 3 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
-[Inbox Kitten](https://inboxkitten.com/)
-[TempMail +](https://tempmail.plus/)
-[TempMail.lol](https://tempmail.lol/)
-[TempMail](https://temp-mail.org/uk/)
-[GmailNator](https://www.gmailnator.com/) *(Temp gmail email)*
### Services for receiving SMS
-[Receive Sms Free](https://receive-sms-free.cc/)
Expand Down Expand Up @@ -225,6 +226,44 @@ def test_handler(letter):
mail.poling()
```

```python
# Temp Mail
from account_generator_helper import TempMail


mail = TempMail()
print('Mail :', mail.get_email()) # Mail : lolerip541@gpipes.com


for _letter in mail.get_inbox():
print('Letter :', _letter) # Letter : (Letter ..)
print('Letter content :', _letter.letter) # Letter content : ...


@mail.letter_handler()
def new_mail(letter):
print('New mail :', letter)


@mail.letter_handler(from_email='den70007.ua@gmail.com')
def test_from(letter):
print('Test from :', letter)


@mail.letter_handler(re_subject='.* test .*')
def test_re_subject(letter):
print('Test re subject :', letter)


@mail.letter_handler(from_email='den70007.ua@gmail.com', subject='Test letter')
def test_handler(letter):
print('Test handler :', letter)


mail.poling()
```


### Receive SMS
```python
# Receive Sms Free
Expand Down
2 changes: 1 addition & 1 deletion account_generator_helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

__author__ = 'Dionis1902'
__email__ = 'den70007.ua@gmail.com'
__version__ = '1.0.12'
__version__ = '1.0.13'
1 change: 1 addition & 0 deletions account_generator_helper/temp_mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .tempmailplus import TempMailPlus, TempMailPlusDomains
from .gmailnator import GmailNator
from .tempmaillol import TempMailLol
from .tempmail import TempMail
42 changes: 42 additions & 0 deletions account_generator_helper/temp_mail/tempmail/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import cloudscraper

from .letter import Letter
from ..exceptions import NotSetEmail, ProblemWithGetEmail
from ..mail import Mail


class TempMail(Mail):
"""
Class for work with https://temp-mail.org/
"""

def __init__(self, proxy=None):
super().__init__(proxy)

self._s = cloudscraper.create_scraper(delay=10, browser="chrome")
if proxy:
self._s.proxies.update(self._proxies)

self.__token = None

def get_email(self):
"""
Get random email address from https://temp-mail.org/
"""

r = (self._s.get if self.__token else self._s.post)('https://web2.temp-mail.org/mailbox',
headers={'Authorization': 'Bearer ' + self.__token} if self.__token else None)
if not r.ok:
raise ProblemWithGetEmail()
if not self.__token:
self.__token = r.json().get('token')
return self.set_email(r.json()['mailbox'])

def get_inbox(self):
if not self._email or not self.__token:
raise NotSetEmail()

r = self._s.get(f'https://web2.temp-mail.org/messages', headers={'Authorization': 'Bearer ' + self.__token})
if r.ok:
return [Letter(self._email, _letter['from'], _letter['subject'], _letter['receivedAt'], _letter['bodyPreview']) for _letter in r.json().get('messages', [])]
return []
19 changes: 19 additions & 0 deletions account_generator_helper/temp_mail/tempmail/letter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re

from ..mail import letter
from datetime import datetime


class Letter(letter.Letter):
def __init__(self, to, from_email, subject, timestamp, body):
if '<' in from_email:
name, from_email = re.findall(r'(.*) <(.*)>', from_email)[0]
else:
name = from_email = from_email

super().__init__(to, name, from_email, subject, datetime.fromtimestamp(timestamp))
self.__body = body

@property
def letter(self):
return self.__body
33 changes: 33 additions & 0 deletions examples/temp_mail/tempmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from account_generator_helper import TempMail


mail = TempMail()
print('Mail :', mail.get_email()) # Mail : lolerip541@gpipes.com


for _letter in mail.get_inbox():
print('Letter :', _letter) # Letter : (Letter ..)
print('Letter content :', _letter.letter) # Letter content : ...


@mail.letter_handler()
def new_mail(letter):
print('New mail :', letter)


@mail.letter_handler(from_email='den70007.ua@gmail.com')
def test_from(letter):
print('Test from :', letter)


@mail.letter_handler(re_subject='.* test .*')
def test_re_subject(letter):
print('Test re subject :', letter)


@mail.letter_handler(from_email='den70007.ua@gmail.com', subject='Test letter')
def test_handler(letter):
print('Test handler :', letter)


mail.poling()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ idna==3.3
requests==2.27.1
urllib3==1.26.9
beautifulsoup4~=4.10.0
pysocks==1.7.1
pysocks==1.7.1
cloudscraper==1.2.69
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='account_generator_helper',
version='1.0.12',
version='1.0.13',
packages=find_packages(),
classifiers=[
'Development Status :: 3 - Alpha',
Expand Down

0 comments on commit e029730

Please sign in to comment.