77π
Are you trying to use a gmail account? Maybe try this then:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your-username@gmail.com'
EMAIL_HOST_PASSWORD = 'your-password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
Then try test (django < 1.4) by
python manage.py shell
>>> from django.core.mail import send_mail
>>> send_mail('test email', 'hello world', to=['test@email.com'])
And if you use django 1.4 use this:
python manage.py shell
>>> from django.core.mail import send_mail
>>> send_mail('test email', 'hello world', 'your@email.com', ['test@email.com'])
If youβre not using a gmail account and still getting problems then just try add the EMAIL_HOST_USER
and EMAIL_HOST_PASSWORD
to what you have.
If you still have issues maybe your network is blocking you. Firewalls on your OS or router.
Thanks to knite for the updated syntax. Throw him a +1 and thanks to pranavk for letting me know about the syntax change in django 1.4
46π
First Create an Application specific password
- Visit your Google Account security page. And Click 2-step verification:
- Click
App passwords
at Google Account security page:
Then add the appropriate values to settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your-username@gmail.com'
EMAIL_HOST_PASSWORD = 'Application spectific password(for eg: smbumqjiurmqrywn)'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
You can use the shell to test it:
python manage.py shell
>>> from django.core.mail import send_mail
>>> send_mail('Test', 'This is a test', 'your@email.com', ['toemail@email.com'],
fail_silently=False)
- [Django]-Building a list in Django templates
- [Django]-How do I include image files in Django templates?
- [Django]-How to write django test meant to fail?
17π
@mongoose_za has a great answer, but the syntax is a bit different in Django 1.4+.
Instead of:
send_mail('test email', 'hello world', to=['test@email.com'])
use
send_mail('test email', 'hello world', 'your@email.com', ['test@email.com'])
The first four arguments are required: subject, message, from_email, and recipient_list.
- [Django]-Django orm get latest for each group
- [Django]-Django form got multiple values for keyword argument
- [Django]-How does the get_or_create function in Django return two values?
4π
- Enable pop3 in gmail settings.
- create application specific password for this django application. (http://support.google.com/accounts/bin/answer.py?hl=en&answer=185833)
- [Django]-">", "<", ">=" and "<=" don't work with "filter()" in Django
- [Django]-In a Django QuerySet, how to filter for "not exists" in a many-to-one relationship
- [Django]-Why does django run everything twice?
3π
I would avoid using GMail. It will work for a few emails, but after that, you may find that all your emails are being rejected or spam-canned. I used Amazonβs βSESβ service with Django-SES to solve this.
- [Django]-Which database engine to choose for Django app?
- [Django]-Django β how to unit test a post request using request.FILES
- [Django]-Difference between auto_now and auto_now_add
1π
In settings.py, Use smtp as backend and not console
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
- [Django]-What's the best way to start learning django?
- [Django]-Disable a method in a ViewSet, django-rest-framework
- [Django]-Why use Django on Google App Engine?
0π
put the following minimal settings in the settings.py or local_settings.py file on your server.
EMAIL_HOST = 'localhost'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
instead of using smtp.gmail.com which imposes lot many limitations, you can have your own mail server.
you can do it by installing your own mailserver:
sudo apt-get install sendmail
- [Django]-Easiest way to rename a model using Django/South?
- [Django]-Django returning HTTP 301?
- [Django]-What does 'many = True' do in Django Rest FrameWork?
0π
First setup the email backend variables in settings.py file.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'your-username@gmail.com'
EMAIL_HOST_PASSWORD = 'your-password'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
Then, create an email object to send the mails.
from django.core import mail
connection = mail.get_connection() # Manually open the connection
connection.open() # Construct an email message that uses the connection
email = mail.EmailMessage( 'Hello', 'Body goes here', 'from@example.com', ['to1@example.com'], connection=connection, )
email.send() # Send the email
connection.close()
- [Django]-Django 1.7 migrations won't recreate a dropped table, why?
- [Django]-Visual Editor for Django Templates?
- [Django]-Django: save() vs update() to update the database?