我设置了一个系统Django /芹菜/ Redis。我用EmailMultiAlternatives发送我的HTML和文本电子邮件。如何通过Celery发送HTML邮件?它不断发送文本/平原
当我发送电子邮件作为请求过程的一部分时,电子邮件以HTML格式发送。所有的运行都很好,它包裹了一个函数。下面的代码:
def send_email(email, email_context={}, subject_template='', body_text_template='',
body_html_template='', from_email=settings.DEFAULT_FROM_EMAIL):
# render content
subject = render_to_string([subject_template], context).replace('\n', ' ')
body_text = render_to_string([body_text_template], context)
body_html = render_to_string([body_html_template], context)
# send email
email = EmailMultiAlternatives(subject, body_text, from_email, [email])
email.attach_alternative(body_html, 'text/html')
email.send()
然而,当我试图运行它作为一个芹菜任务,如下图所示,它只是被作为“text/plain的”。可能是什么问题呢?或者我能做些什么来了解更多信息?任何提示或解决方案,不胜感激。
@task(name='tasks.email_features', ignore_result=True)
def email_features(user):
email.send_email(user.email,
email_context={'user': user},
subject_template='emails/features_subject.txt',
body_text_template='emails/features_body.txt',
body_html_template='emails/features_body.html')
谢谢。重启似乎有帮助。 – 2012-07-27 00:03:22