Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6618281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:48:40+00:00 2026-05-25T20:48:40+00:00

My Django application sends out quite a bit of emails and I’ve tried testing

  • 0

My Django application sends out quite a bit of emails and I’ve tried testing it thoroughly. However, for the first few months, I’d like to log all outgoing emails to ensure that everything is working smoothly.

Is there a Django module that allows me to do this and makes the outgoing emails visible through the administration panel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:48:40+00:00Added an answer on May 25, 2026 at 8:48 pm

    I wrote a custom email backend which logs the stuff to a model.

    Here’s my backend:

    from django.core.mail.backends.smtp import *
    from django.db import transaction
    
    from modules.common.models import *
    
    class LoggingEmailBackend(EmailBackend):
        """
        A wrapper around the SMTP backend that logs all emails to the DB.
        """
        def send_messages(self, email_messages):
        """
        A helper method that does the actual logging
        """
        with transaction.commit_on_success():
    
            for email_message in email_messages:
    
                email_record = Email.objects.create(
                    to='; '.join(email_message.recipients()),
                    subject=email_message.subject, body=email_message.body,
                )
    
                try:
                    return super(LoggingEmailBackend, self)._send(
                        email_message
                    )
                except:
                    email_record.ok = False
                    return False
                finally:
                    email_record.ok = True
                    return True
    

    Here’s the model:

    class Email(models.Model):
        """
        Model to store all the outgoing emails.
        """
        when = models.DateTimeField(
            null=False, auto_now_add=True
        )
        to = models.EmailField(
            null=False, blank=False,
        )
        subject = models.CharField(
             null=False, max_length=128,
        )
        body = models.TextField(
            null=False, max_length=1024,
        )
        ok = models.BooleanField(
            null=False, default=True,
        )
    

    Here’s my model:

    from django.contrib import admin
    
    from modules.common.models import *
    
    class EmailAdmin(admin.ModelAdmin):
        """
        Admin part for managing the the Email model
        """
        list_display = ['to', 'subject', 'ok',]
        list_filter = ['ok']
        readonly_fields = ['when', 'to', 'subject', 'body', 'ok']
        search_fields = ['subject', 'body', 'to']
    
        def has_delete_permission(self, request, obj=None):
            return False
    
        def has_add_permission(self, request):
            return False
    
    
    admin.site.register(Email, EmailAdmin)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating small django application which holds some few questions (and answers for
The Django-based web application I'm working on is translated to a few different languages.
I need to test that my Django application sends e-mails with correct content. I
My Django application has 10,000 users, all with emails. I would like to send
I am making my first Django application and am running into some AJAX issues.
My django application is having a handler for each functionality (e.g. Salesinvoice handler for
My django application has become painfully slow on the production. Probably it is due
I am developing a Django application, which is a large system that requires multiple
HI I have a django application running on app engine and I want to
I am developing an Django application using the Django 1.3.1 release : https://code.djangoproject.com/browser/django/tags/releases/1.3.1 I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.