开发者

The email_from in Django send_mail function not working [duplicate]

This question already has answers here: How to change from-address when using gmail smtp server (6 answers) Closed 3 years ago.

I put a contact form in my site, and I have this in my settings.py

# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail@gmail.com'
EMAIL_HOST_PASSWORD = '****'
EMAIL_PORT = 587

And this in my views.py

name = form.cleaned_data['name']
email = form.cleaned_data['email']
message = form.cleaned_data['message']
subject = 'Email from ' + name
content = name + '\r\n' + email + '\r\n\r\n' + message

sen开发者_运维技巧d_mail(subject, content, email, ['me@myemail.com'])

It all works correctly, i get the email with all the information, but, the email comes from myemail@gmail.com even though the from_email parameter has the email var with the senders email.

It doesn't work that way or i'm doing something wrong?

I wanted to get the email from the sender, so y can just reply to it, like i do in PHP.

Thank you.


Gmail will not let you spoof where the email came from.

per user iAn in a similar post

The short answer - you can't.

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.

You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.

If you are intent on using gmail then you could:

Setup a dedicated "myapp@gmail.com" account If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "myapp@mydomain.com" account.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜