You can solve this problem with the function. Create a function that performs both functions:
- Make sure you can get what you want.
- Make sure the message is sent.
Or you can make even heavier plumbing. Make sure you document it well and try to get other people to not try it at home for every useless purpose; instead, contact the Django or Django-mailer teams and ask them if they can arrange a better solution.
decorate the EmailMessage class from the django.core.mail module: make sure that when the message is sent successfully, the information you want is also delivered to another place.
# wrappedmailer.py from django.core.mail import EmailMessage class WrappedEmailMessage(object): def __init__(self, message): self.__message = message
Then, when your application is initialized, before downloading django-mailer you can do the following:
import django.core.mail import newmailer django.core.mail.EmailMessage = newmailer.WrappedEmailMessage
The django.core.mail module remains in the cache as part of the same Python process, so whenever django.core.mail is imported, the EmailMessage class will actually be the WrappedEmailMessage class.
source share