So I've been delayed on my promised Phoenix for Django Devs post, but I've got something else fun instead.

One of the challenges when developing Django apps is email testing.  Having to actually send emails and check in your real email client is kind of a hassle and always risks accidentally sending an email to an incorrect person.  You can use something like mailtrap.io, which at least ensures the email will never get to an incorrect person and provides some great functionality, but you still need a network connection and have somewhere else to log in to view the data.

To solve the issue for myself, I have created Django Mail Viewer.  This is a Django app which provides a set of views and mail backends for locally trapping email and viewing the html, raw html, plain text, and attachments.  Currently there is a single locmem email backend based on Django's built in locmem backend.  It stores the emails in local memory, but stores the python email.message.Message objects rather than Django's EmailMessage objects.  This backend requires that the emails be sent in the same process as your view is being served from.  In the very near future I plan to add a cache based backend which will make this usable in a more distributed system, such as if you are using Django Channels or just want to send some test emails from a Python shell or Django management command.

View the documentation on Read The Docs or have a look at the source on GitHub.