`
Sep 15

DjangoWhile 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.

  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@mangoorange.com'])
    email.save()

Hope it help someone :) Reference here.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • Technorati
  • Live
  • NewsVine
  • YahooMyWeb
  • e-mail

written by mangoorange \\ tags: , , ,


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@mangoorange.com'])
    email.send()

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

Leave a Reply

You must be logged in to post a comment.