How to send email via Django?

0 votes

In my settings.py, I have the following:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False

My email code:

from django.core.mail import EmailMessage
email = EmailMessage('Hello', 'World', to=['user@gmail.com'])
email.send()

If I setup a debugging server via python -m smtpd -n -c DebuggingServer localhost:1025, I can see the email in my terminal.

However, how do I actually send the email not to the debugging server but to user@gmail.com?

May 6 in Python by kartik
• 11,890 points
41 views

1 answer to this question.

0 votes

Hello @kartik,

I use Gmail as my SMTP server for Django. Much easier than dealing with postfix or whatever other server. I'm not in the business of managing email servers.

In settings.py:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'deyneeraj666@gmail.com'
EMAIL_HOST_PASSWORD = 'password'

Hope this works!!

Thank You!!

answered May 6 by Niroj
• 23,950 points

Related Questions In Python

+5 votes
0 answers

How to send sms to users from Django application?

I'm looking for an option to send ...READ MORE

Nov 13, 2018 in Python by Manu
• 170 points
3,201 views
0 votes
1 answer

How do you configure Django to send mail through Postfix?

You can do this by adding  settings.py ...READ MORE

answered Feb 25, 2019 in Python by SDeb
• 13,250 points
1,302 views
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,810 points
314 views
0 votes
1 answer

How to create transaction in GnuCash in response to an email?

Here's a template, along with a couple ...READ MORE

answered Sep 5, 2018 in Python by Priyaj
• 57,530 points
108 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 963 views
0 votes
0 answers
0 votes
1 answer

How to query as GROUP BY in django?

Hii, Django does not support free group by ...READ MORE

answered Apr 23 in Python by Niroj
• 23,950 points
34 views
0 votes
1 answer

How to perform HTML decoding/encoding using Python/Django?

Hello, For html encoding, there's cgi.escape from the standard library: >> ...READ MORE

answered May 6 in Python by Niroj
• 23,950 points
206 views