我试图在Django 1.6中将send_mail()
方法更改为EmailMessage
方法。
这就是我的方法在send_mail()
# Send email
if user_profile.contracting:
subject = _('Your question on project {} has been answered')
body = _('You can read your answer here {}')
email = question.user.email
else:
subject = _('Your have a new question on project {}')
body = _('You can read your question here: {}')
email = project.user.email
send_mail(subject.format(project.name),
body.format(
os.environ.get('CURRENT_URL') + '/' +
reverse('projects_id', args=(project.id,))[1:]),
'no-responder@contratlos.com', [email])
return HttpResponseRedirect(reverse('projects_id',
args=(project.id,)))
现在,尝试更改它,它不会抛出任何错误,但不会发送任何电子邮件:
# Send email
if user_profile.contracting:
subject = _('Your question on project {} has been answered')
body = _('You can read your answer here {}')
email = question.user.email
else:
subject = _('Your have a new question on project {}')
body = _('You can read your question here: {}')
email = project.user.email
correo = EmailMessage(subject.format(project.name),
body.format(
os.environ.get('CURRENT_URL') + '/' +
reverse('projects_id', args=(project.id,))[1:]),
'no-responder@contratlos.com', [email],['kristian.koci@gmail.com'])
return HttpResponseRedirect(reverse('projects_id',
args=(project.id,)))
我在这里找不到什么东西?
提前致谢!
答案 0 :(得分:1)
EmailMessage
是用于创建自定义电子邮件的便捷类。但是,与send_mail()
不同,您需要明确调用.send()
才能实际发送消息:
correo.send()