Reputation: 771
I have a site I'm building using Django and I've encountered the following conundrum. I have a backend email that we will call [email protected]. Now I also have a domain email that forwards directly to [email protected] which is called [email protected].
Currently I have my Django Email setting set up as follows:
EMAIL_HOST_USER="[email protected]"
EMAIL_HOST_PASSWORD="password"
This works fine, but I want to have the email sent out from '[email protected]'.
Including the Python community as a whole as maybe the issue can be resolved outside of Django mail wrapper functions.
How can I set up this redirection? Meaning, how can I send out emails under the alias '[email protected]' when my true email configured in the Django backend is [email protected] ?
Upvotes: 4
Views: 2748
Reputation: 1232
Taken from django documentation In two lines:
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', '[email protected]',
['[email protected]'], fail_silently=False)
Mail is sent using the SMTP host and port specified in the EMAIL_HOST and EMAIL_PORT settings. The EMAIL_HOST_USER and EMAIL_HOST_PASSWORD settings, if set, are used to authenticate to the SMTP server, and the EMAIL_USE_TLS and EMAIL_USE_SSL settings control whether a secure connection is used.
Upvotes: 0
Reputation: 799062
settings.EMAIL_HOST_USER
is only used to authenticate with the SMTP server. The third argument of django.core.mail.send_mail()
is the From:
address.
Upvotes: 9