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 に答える