Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Django build-in send_mail function working with html by default

I want to substitute build-in send_mail function, that works only with plain-text emails, with my own smart send_mail function, that generates both html and plain-text versions automatically. Everything works as expected for my own emails, defined in my own application. I can do it in views.py in this fashion:

from django.core import mail
from utils import send_mail as send_html_mail
mail.send_mail = send_html_mail

But the problem still appears with emails of third-side applications. There all imports already completed before my code with monkey-patching of send_mail function.

Is it possible to override this function before all imports of all django applications? Or may be there is another solution of this issue. I really don't want to patch code with sending emails of these third-party applications. It's much easy just to put html-template.

like image 286
ramusus Avatar asked Jan 20 '23 18:01

ramusus


1 Answers

Django 1.2 allows for pluggable email backends: http://docs.djangoproject.com/en/1.2/topics/email/#defining-a-custom-e-mail-backend

like image 111
Mark Lavin Avatar answered Jan 30 '23 19:01

Mark Lavin