-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmyemail.py
33 lines (28 loc) · 981 Bytes
/
myemail.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
from itsdangerous import URLSafeTimedSerializer
import smtplib
from email.mime.text import MIMEText
from api import app
def generate_confirmation_token(email):
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY'])
return serializer.dumps(email, salt=app.config['SECURITY_PASSWORD_SALT'])
def confirm_token(token, expiration=3600):
serializer = URLSafeTimedSerializer(app.config['SECRET_KEY'])
try:
email = serializer.loads(
token,
salt=app.config['SECURITY_PASSWORD_SALT'],
max_age=expiration
)
except:
return False
return email
def send_email(to, subject, template):
me = "Woording <[email protected]>"
msg = MIMEText(template, 'html')
msg["From"] = me
msg["Subject"] = subject
msg["To"] = to
server = smtplib.SMTP('woording-mail')
server.login("[email protected]", "SecretPassw0rd")
server.sendmail(me, [to], msg.as_string())
server.quit()