Skip to content

Commit

Permalink
edited docs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpoi committed Dec 11, 2024
1 parent 8e19454 commit 6cfdc9b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions docs/source/signals.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Signals
============

Each time an email is added to the mail queue, Post Office emits a special `Django signal <https://docs.djangoproject.com/en/5.1/topics/signals/>`_.
Each time an email is added to the mail queue, Sendmail emits a special `Django signal <https://docs.djangoproject.com/en/5.1/topics/signals/>`_.
Whenever a third party application wants to be informed about this event,
it shall connect a callback function to the Post Office's signal handler ``email_queued``, for instance:
it shall connect a callback function to the Sendmail signal handler ``email_queued``, for instance:

.. code-block:: python
Expand All @@ -18,5 +18,24 @@ The Emails objects added to the queue are passed as list to the callback handler

**Note** when you use :ref:`mail.send_many()` you will get emails batch by batch.

If you are using :ref:`Email Tracking` feature and want to extend the behavior of
email open and click views you can connect to ``email_opened`` and ``email_clicked`` signals.

For example to save the latest opened and clicked timestamps instead of first ones:

.. code-block:: python
from django.dispatch import receiver
from sendmail.signals import email_opened, email_clicked
from django.utils import timezone
@receiver(email_opened)
def change_opened_at(sender, email, **kwargs):
email.opened_at = timezone.now()
email.save()
@receiver(email_clicked)
def change_clicked_at(sender, email, **kwargs):
email.clicked_at = timezone.now()
email.save()

0 comments on commit 6cfdc9b

Please sign in to comment.