Sep 15

While I was learning how to use django-registration app, I discover in the tutorial that I need to knowdjango.sh-600x600[1] 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.

  1. Create a project, django-admin.py startproject gmail
  2. 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
  3. Run interactive mode, python manage.py shell
  4. Import the EmailMessage module,
    from django.core.mail import EmailMessage
  5. Send the email,
    email = EmailMessage('Subject', 'Body', t=['mickeyckm@mangooranges.com'])
    email.save()

Hope it help someone 🙂 Reference here.

written by mangoorange \\ tags: , , ,


Best Wordpress Hosting Providers - 2014

All three hosts offer FREE 1-click Wordpress installs making them the best Wordpress hosting providers. For more web hosting reviews be sure to check out AlreadyHosting.com.

 #1
#2 
 #3
#1 - Bluehost 
Bluehost Review
#2 - iPage 
iPage Review
#3 - HostMetro 
HostMetro Review


3 Responses to “Sending email via Gmail in Django”

  1. 1. Louis Says:

    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 😉

  2. 2. Ollie Plonka Says:

    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.

  3. 3. Selim Ober Says:

    Obvious but still…
    There are 2 errors on the 5th step. It should be:

    email = EmailMessage(‘Subject’, ‘Body’, to=[‘mickeyckm@mangooranges.com’])
    email.send()

    send() instead of save(),
    to instead of t

Leave a Reply

You must be logged in to post a comment.