Monday, April 22, 2013

Debugging SMTP communication in Django

After a while getting trouble with the sending email functionality of my Django app, I read the core of Django and python's smtplib module to find a way to debug the smtp connection. I only need to set the debug level = True when we create the connection in the email backend of Django (or in whatever email backend you're using):

django.core.mail.backend.smtp:

----------------------------------------------

def open(self):

     ......

     self.connection.set_debuglevel = True

    .......

----------------------------------------------

When I send the email from my Django app, the console will give me some useful information

Read more about the Django core email backend: https://github.com/django/django/blob/master/django/core/mail/backends/smtp.py

and the smtplib module: http://docs.python.org/2/library/smtplib.html

 

It saved my day! \m/\m/\m/