-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (21 loc) · 828 Bytes
/
utils.py
File metadata and controls
27 lines (21 loc) · 828 Bytes
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
import smtplib
import os
from random import randint
def generate_token(digits):
range_start = 10**(digits-1)
range_end = (10**digits)-1
return str(randint(range_start, range_end))
def send_email_with_token(email, token):
server = smtplib.SMTP_SSL('smtp.yandex.com:465')
server.ehlo()
server.login(os.environ["EMAIL_USERNAME"], os.environ["EMAIL_PASSWORD"])
message = 'Subject: NISB Password Reset\n\n' + \
'An attempt was made to reset the password.\n' + \
'Please use the following as token for the same\n' + token + \
'\nIgnore if not by you.'
server.sendmail(os.environ["EMAIL_USERNAME"], email, message)
server.quit()
return True
# if __name__ == "__main__":
# token = (generate_token(6))
# send_email_with_token("mridul.kepler@gmail.com",token)