Thursday 29 December 2011

Sending email via Gmail in Django

While I was learning how to use django-registration application, I need to know that how to send an email for the user to activate the registration.
During this post I want to show how to test it using shell, 
  1. Create a project, django-admin.py startproject pjtname
  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 = 'your password'
         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', to=['receiver email id'])
         email.send()

No comments:

Post a Comment