1

背景 :-

我的电子邮件后端是这样的:

EMAIL_HOST ='smtp.gmail.com' 
EMAIL_PORT = 587
EMAIL_HOST_USER = 'feedback@example.com' 
EMAIL_HOST_PASSWORD = 'XXX' 
EMAIL_USE_TLS = True

问题:-

我正在使用 EmailMultiAlternatives 发送 html 邮件。现在我想定义 auth_user 和 auth_password 以便我可以更改“来自”。基本上我想超越 EMAIL_HOST_USER,但希望 from_email 冗长,即“支持团队”。怎么做到呢?

subject, from_email, to = "hello", 'Support Team','to_user@gmail.com'
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 = 'support@example.me',auth_password = 'XXX')
4

1 回答 1

4

你可以这样做:

from django.core.mail import *

#retrieve emailbackend from settings.py
connection = get_connection(username, password)
#change connection parameters
connection.host='XXX'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to], connection)
msg.attach_alternative(html_content, "text/html")
于 2012-01-19T16:55:36.517 回答