Pergunta

I have set up the django smtp backend to use gmail smtp. and it sends email perfectly, But there is one problem.

The authentication I use for gmail smtp is different then the from_email, still when I receive an email I see the from email id as the smtp auth email.

example: my settings are as follow:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER= 'something@somedomain.com'
EMAIL_HOST_PASSWORD= 'password_for_something_at_gmail_com'

and to send an email I did

send_mail(subject=subject, message="test", from_email="other@mydomain.com",
recipient_list=to, fail_silently=False)

this works but the received email does not show

from : other@mydomain.com 

it shows

from: something@somedomain.com

How do I make sure it shows other@mydomain.com.

NOTE: somedomain.com is connected with google apps and mydomain.com is alias with it and other@mydomain.com is just an fwd email id.

Outras dicas

You can override From header with below email sending code.

from django.core.mail import EmailMessage

EmailMessage(subject, message, "<"+str(from_email)+">", recipient_list)

Note: Actually it will send email from the email id which you configured in settings.py file but From header will show from_email address

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top