-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendmail.py
45 lines (39 loc) · 1.58 KB
/
sendmail.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
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from app import *
from flask import url_for
import os
from flask_mail import Mail,Message
app.config['MAIL_SERVER']='smtp.googlemail.com'
app.config['MAIL_PORT']=587
app.config['MAIL_USE_TLS']=True
app.config['MAIL_USERNAME']=os.getenv("USER_EMAIL") #generate using your google account whose email id you will use to send links to other user
app.config['MAIL_PASSWORD']=os.getenv("USER_PASSWORD") #generate same as above
mail=Mail(app)
def get_token(user):
s=Serializer(app.config["SECRET_KEY"],240)
return s.dumps({'user_id':user[0]}).decode('utf=8')
def verify_token(token):
s=Serializer(app.config["SECRET_KEY"])
try:
user_id=s.loads(token)['user_id']
except:
return None
c.execute("""SELECT * FROM user WHERE id=?""",(user_id,))
val=c.fetchone()
return val
def send_email(user):
token=get_token(user)
msg=Message('Reset Instaclone Password',sender='instaclone@demo.com',recipients=[user[2]])
msg.body=f'''To reset your InstaClone password ,visit following link:
{url_for('change',token=token,_external=True)}
If you did not make this request then just ignore.
'''
mail.send(msg)
def send_email1(user):
token=get_token(user)
msg=Message('Verify InstaClone account',sender='instaclone@demo.com',recipients=[user[2]])
msg.body=f'''To verify your InstaClone account,visit following link:
{url_for('confirm_email',token=token,_external=True)}
If you did not make this request then just ignore.
'''
mail.send(msg)