如何在 Django 中为 EmailMultiAlternatives 自定义电子邮件后端
背景:-
我的电子邮件后端是这样的:
EMAIL_HOST ='smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'XXX'
EMAIL_USE_TLS = True
问题:-
我正在使用 EmailMultiAlternatives 发送 html 邮件。 现在我想定义 auth_user 和 auth_password 以便我可以更改“from”。基本上我想覆盖 EMAIL_HOST_USER,但希望 from_email 更详细,即“支持团队”。怎么办呢?
subject, from_email, to = "hello", 'Support Team','[email protected]'
text = "hello"
html = "<strong>hello</strong>"
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False,auth_user = '[email protected]',auth_password = 'XXX')
Background :-
My email Backend is something like this:
EMAIL_HOST ='smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'XXX'
EMAIL_USE_TLS = True
Problem:-
I am using EmailMultiAlternatives to send html mails.
Now I want to define auth_user and auth_password so that i can change the "from". Basically I want to over ride the EMAIL_HOST_USER, but want the from_email to be verbose, i.e. 'Support Team'. How can it be done?
subject, from_email, to = "hello", 'Support Team','[email protected]'
text = "hello"
html = "<strong>hello</strong>"
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False,auth_user = '[email protected]',auth_password = 'XXX')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
You could do something like this: