Django send_mail smtp gmail

118 views
Skip to first unread message

ofeyofey

unread,
May 18, 2016, 6:47:31 PM5/18/16
to Django users
Hi,

I have set up smtp with a gmail account. When I use send_mail the from email is not showing up in the account receiving the email.

Django settings.py

# DEFAULT_FROM_EMAIL = 'sen...@gmail.com'
EMAIL_BACKEND
= 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST
= 'smtp.gmail.com'
EMAIL_PORT
= 587
EMAIL_HOST_USER
= 'sen...@gmail.com'
EMAIL_HOST_PASSWORD
= '**********'
EMAIL_USE_TLS
= True

Using 

$ python manage.py shell

I send the mail as follows,

>>> from django.core.mail import send_mail
>>> send_mail('subject is', 'message is and is not 12342', 'from...@gmail.com', ['sen...@gmail.com'])
1
>>>

I am receiving this email in my gmail account, incidently which is the same gmail account used for the smtp, but the from email is showing up as the sen...@gmail.com and should be from...@gmail.com

Any help would be greatly appreciated,

Thanks,

Shane



James Schneider

unread,
May 18, 2016, 7:11:13 PM5/18/16
to django...@googlegroups.com


> >>> from django.core.mail import send_mail
> >>> send_mail('subject is', 'message is and is not 12342', 'from...@gmail.com', ['sen...@gmail.com'])
> 1
> >>>
>
> I am receiving this email in my gmail account, incidently which is the same gmail account used for the smtp, but the from email is showing up as the sen...@gmail.com and should be from...@gmail.com
>

The GMail servers will automatically override any provided envelope or message sender address value and replace it with the address used to authenticate to SMTP due to name space collisions and spam protection. There's no way to override this behavior. You'll need to find another mail relay service if this is critical.

-James

Reply all
Reply to author
Forward
0 new messages