-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
49 lines (39 loc) · 1.53 KB
/
Copy pathtasks.py
File metadata and controls
49 lines (39 loc) · 1.53 KB
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
import uuid
from celery import Celery
import App.ext
from flask import request
from flask_mail import Message
from App.helper import md5_crypt
try:
import manage
except:
pass
from App import helper, dao
from App.models import User
app = Celery('tasks',broker='redis://:8227099@120.79.223.66:6379/6')
@app.task
def sendMail(uId,url):
with manage.app.test_request_context():
u = dao.getById(User, uId)
print('查到的用户', u)
token = md5_crypt(str(uuid.uuid4()))
# 将token设置到redis缓存中
App.ext.cache.set(token, u.id, timeout=10 * 60) # 允许10分钟内来激活用户
print('toke', token)
print('id', u.id)
active_url = url + 'account/?opt=active&token=' + token
print('路径', active_url)
# 发送邮件
msg = Message(subject='淘票票用户激活',
recipients=[u.email],
sender='zhaoairong0108@163.com')
msg.html = "<h1>{} 注册成功!</h1><h3>请先<a href={}>激活</a>注册账号</h3> <h2>或者复制地址到浏览器: {}</h2>".format(u.name,
active_url,
active_url)
try:
print(msg.html)
App.ext.mail.send(msg)
print('邮件已发送')
except Exception as e:
print(e)
print('邮件发送失败')