-
Notifications
You must be signed in to change notification settings - Fork 8
/
bot.py
43 lines (42 loc) · 1.63 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import telebot
import redis
r = redis.Redis('localhost')
from tempmail import TempMail
token = 'TOKEN'
bot = telebot.TeleBot(token)
user = bot.get_me().username
@bot.message_handler(commands=['start'])
def start(m):
# start text
text = 'Hi.\nWelcome to {}.\nCommands: \n/newmail: For making a new Email.\n/mails: For reading new emails.'.format(user)
bot.send_message(m.chat.id, text)
@bot.message_handler(commands=['newmail'])
def newmail(m):
#initialize Temp-Male and making a new Email.
tm = TempMail()
email = tm.get_email_address()
r.set('email:{}:mail'.format(str(m.from_user.id)), email)
bot.send_message(m.chat.id, 'Your new Email: '+email)
@bot.message_handler(commands=['mails'])
def mails(m):
try :
#initialize Temp-Mail and read recieved Mails.
mail = r.get('email:{}:mail'.format(str(m.from_user.id)))
if not mail:
bot.send_message(m.from_user.id, 'Make an email first.\nUse /newmail')
return
parts = mail.split('@')
tm = TempMail(login=parts[0], domain='@'+parts[1])
mails = tm.get_mailbox()
if not mails :
bot.send_message(m.from_user.id, 'There is no email...')
else:
if 'error' in mails :
bot.send_message(m.from_user.id, 'There is no email...')
else:
print mails
for i in mails:
bot.send_message(m.from_user.id, 'Mail from: '+i['mail_from']+'\n\nSubject: '+i['mail_subject']+'\n\nText: ' +i['mail_text'])
except:
bot.send_message(m.from_user.id, 'There is no email...')
bot.polling()