Django EmailMessgae() 错误:MIMEPart.__init__()
这是我的视图文件:
我已经制作了一个令牌文件来生成链接 和信息文件,了解诸如 EMAIL_HOST_USER
等详细信息。
current_site = get_current_site(request)
email_subject = "Confirm your email @XYZ"
message2 = render_to_string('email_confirmation.html',{
'name': myuser.first_name,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(myuser.pk)),
'token': generate_token.make_token(myuser),
})
email = EmailMessage(
email_subject,
message2,
settings.EMAIL_HOST_USER,
[myuser.email],
)
email.fail_silently=False
email.send()
This is my views file:
I have made a token file to generate a link
and info file for details like EMAIL_HOST_USER
and etc.
current_site = get_current_site(request)
email_subject = "Confirm your email @XYZ"
message2 = render_to_string('email_confirmation.html',{
'name': myuser.first_name,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(myuser.pk)),
'token': generate_token.make_token(myuser),
})
email = EmailMessage(
email_subject,
message2,
settings.EMAIL_HOST_USER,
[myuser.email],
)
email.fail_silently=False
email.send()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也有同样的问题,但是,事实证明我正在导入
EmailMessage
类。而不是这样做:
使用:
Had this same issue as well, but, it turned out that I was importing the
EmailMessage
class.Instead of doing this:
Use:
EmailMessage(...)< /code>
[Django-doc]
没有任何名为
send_mail()
的方法,它必须是send()
并且EmailMessage
没有任何名为fail_silently
的属性,它是传递给send()
方法的参数,因此最终您的代码看起来像这样EmailMessage(...)
[Django-doc] don't have any method named assend_mail()
it has to besend()
andEmailMessage
don't have any attribute named asfail_silently
it's a parameter passed tosend()
method so finally your code will look like this