Question

In Django, I have an app that send email through an gmail account. This is my settings.py configuration

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'thepassword'
EMAIL_PORT = 587

And the way to send emails (in views.py):

from_email = 'user@gmail.com' #look that is equal to EMAIL_HOST_USER
template_html = 'my_template.html'
subject = u'The subject'

html_content = render_to_string(template_html, {})

msg = EmailMultiAlternatives(subject, html_content, from_email, ['the_gmail_user@gmail.com'])
msg.attach_alternative(html_content, "text/html")
msg.send()

The user always receive as SPAM. It's something that I'm doing wrong?

Thanks!

P.s: The same issue occurs in Django 1.4, 1.5 and 1.6, so it's version agnostic

Was it helpful?

Solution

Nothing wrong with your code...

Could be that your email has been flagged as spam by other users, or by Google (sending too many? Message content?). Try a different email service? Gmail isn't really designed for application level email service, but rather to be used by individuals.

I've recently switched to MailGun and their free tier has enough capacity. There are other options out there as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top