celery异步发送邮件使用templates中的邮件模板:
1、你必须在templates中有相应的模板,email/XXXXX.html
2、在task中写入异步任务
@shared_task
def requestemail(message,mail):
subject = 'XXXXX'
send_mail(subject=subject, message=message,
from_email=EMAIL_HOST_USER, recipient_list=[mail,],
html_message=message)
3、在视图函数中加载模板,并发送邮件
message = loader.render_to_string(
'email/XXXXX.html',
{
'user': user,
'wisher': wisher,
'book': book,
}
)
requestemail.delay(message, email)