One of the common functionalities in Django applications is to send emails, such as for user password resets.
Since Python comes with it’s own SMTP, it’s easy to redirect the emails from the local Django application being developed to this dummy mail server and see the emails on the console.
Here’s how to do it:
- Run Python SMTP with this command line:
python -m smtpd -n -c DebuggingServer localhost:1025
- Define Django email server as:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
And that’s it. All emails sent will be seen on the console where you’r running the Python SMTP.
This technique is actually quite useful since you can use this for any application you are developing locally.
Redirect to Console
There’s another way to see the emails on the console with no dependencies.
To do so, just configure the email to use the console email backend.
This will actually redirect all emails to the standard output, which usually is the console.
Redirect to File
Another approach is to redirect the emails into a local file for prior usage.
To do so, just configure the email to use the file email backend.
EMAIL_FILE_PATH = '/tmp/app-messages' # change this to a proper location
This will write all emails into separate files located in
and you can analyze them latter.