forked from 2series/smart-banking-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail.py
executable file
·49 lines (49 loc) · 1.19 KB
/
send_mail.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
44
45
46
47
48
49
#!/usr/bin/python
import private_data
from smtplib import SMTP_SSL as SMTP
from email.mime.text import MIMEText
import random
from config import connect_to_database
class Mail:
USERNAME = private_data.admin_email
PASSWORD = private_data.admin_password
def send_mail(self,user,sub,cont):
SMTPserver = 'smtp.gmail.com'
sender = private_data.admin_email
destination = user
text_subtype = 'html'
content=cont
subject=sub
try:
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(self.USERNAME, self.PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
return "11"
finally:
conn.quit()
except Exception:
return "-99"
def send_otp_mail(self,user):
otp=""
for i in range(0,6):
otp+="%s"%(random.randint(0,9))
sub="OTP"
cont="Your OTP is: <b>%s</b>"%otp
conn,cursor=connect_to_database()
sql="update customers SET last_otp='%s' where email='%s'"%(otp,user)
try:
cursor.execute(sql)
conn.commit()
if self.send_mail(user,sub,cont)=="11":
return otp
return -99
except:
conn.rollback()
return -99
finally:
conn.close()