Email Notification with Signals

A snippet showing how to send emails on post_save with signals.


from django.core.mail import send_mail
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Comment

@receiver(post_save, sender=Comment)
def send_email_on_comment(sender, instance, created, **kwargs):
    if created:
        send_mail(
            'New Comment',
            f'A new comment was added: {instance.text}',
            '[email protected]',
            ['[email protected]']
        )
      
Explanation:
  • A post_save signal is triggered when a new Comment is added.
  • Sends an email automatically when a new Comment is added.
  • Category Signals
  • Total Views 898
  • Last Modified 13 May, 2026
  • Tags #signals #email #notification #automation
Previous snippet
One-Time Signal Execution
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.