|
Sep
15
|
While I was learning how to use django-registration app, I discover in the tutorial that I need to know how to send an email for the user to activate the registration.
Thanks to folk at the Django chatroom, they advice me to google 'django gmail' and I discover a post at nathanostgard.com that show roughly how to do it. Here I'm going to extend a little on how to test it using shell.
- Create a project, django-admin.py startproject gmail
- Edit settings.py with code below:
EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'youremail@gmail.com' EMAIL_HOST_PASSWORD = 'yourpassword' EMAIL_PORT = 587
- Run interactive mode, python manage.py shell
- Import the EmailMessage module,
from django.core.mail import EmailMessage - Send the email,
email = EmailMessage('Subject', 'Body', t=['mickeyckm@mangoorange.com']) email.save()
Hope it help someone
Reference here.
3 Responses to “Sending email via Gmail in Django”
Leave a Reply
You must be logged in to post a comment.



December 15th, 2008 at 2:17 pm
Hey, thanks for the post – I am doing the same thing that you were doing actually – setting up registration on the site.
I found that the order of the email settings matter.
EMAIL_HOST = ‘smtp.gmail.com’
EMAIL_PORT = 587
EMAIL_HOST_USER = ‘myemail@gmail.com’
EMAIL_HOST_PASSWORD = ‘mypassword’
EMAIL_USE_TLS = True
Using this order I couldn’t send the email, but using the order you have above, I can send it.
I’d be interested to know how the registration app went for you – that’s my next challenge
April 27th, 2009 at 3:00 pm
It sounds like you’re creating problems yourself by trying to solve this issue instead of looking at why their is a problem in the first place.
August 27th, 2009 at 4:46 am
Obvious but still…
There are 2 errors on the 5th step. It should be:
email = EmailMessage(‘Subject’, ‘Body’, to=['mickeyckm@mangoorange.com'])
email.send()
send() instead of save(),
to instead of t