Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The email_from in Django send_mail function not working [duplicate]

Tags:

django

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 = '[email protected]'
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

send_mail(subject, content, email, ['[email protected]'])

It all works correctly, i get the email with all the information, but, the email comes from [email protected] 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.

like image 371
ramono Avatar asked Jul 23 '11 20:07

ramono


1 Answers

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 "[email protected]" account If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "[email protected]" account.

like image 186
Andy Avatar answered Oct 20 '22 18:10

Andy