For my current satchmo store, I would like to send html email instead of all the txt email. By the looks of the satchmo_store account registration code, all the emails are hardcoded and uses .txt format instead of html format. e.g. mail.py
"""Sends mail related to accounts."""
from django.conf import settings
from django.utils.translation import ugettext
from satchmo_store.mail import send_store_mail
from satchmo_store.shop.models import Config
from satchmo_store.shop.signals import registration_sender
import logging
log = logging.getLogger('satchmo_store.accounts.mail')
# TODO add html email template
def send_welcome_email(email, first_name, last_name):
"""Send a store new account welcome mail to `email`."""
shop_config = Config.objects.get_current()
subject = ugettext("Welcome to %(shop_name)s")
c = {
'first_name': first_name,
'last_name': last_name,
'site_url': shop_config.site and shop_config.site.domain or 'localhost',
'login_url': settings.LOGIN_URL,
}
send_store_mail(subject, c, 'registration/welcome.txt', [email],
format_subject=True, sender=registration_sender)
I know you can change the last line to the following in order to make it work:
send_store_mail(
subject=subject,
context=c,
template='registration/welcome.txt',
recipients_list=[email],
format_subject=True,
sender=registration_sender,
template_html='registration/welcome.html')
However, it would be in my best interest not to touch the code in Satchmo app for the upgrade purpose in the near future.
Does anyone know what would be the ideal way to override this function or enable the html email for all the registration related functions without touching the satchmo app?
Thanks in advance.
I have done similar changes to Satchmo internals in the following way:
It should be possible to copy the relevant file from the Satchmo installation into your django application. If you set up your Satchmo shop according to this recommendation, that would likely mean copying satchmo/apps/satchmo_store/accounts/mail.py to /localsite/accounts/mail.py. The idea is to automatically load the local copy instead of the original.
In your local copy of mail.py you could then replace the send_store_email() function. Keep a note so that you will remember your changes when it comes to a Satchmo upgrade. Quite likely the original file will still be the same, and your override will work even with future versions.
In other cases when you have to change some class behaviour you can also subclass the original class with one changing only the relevant methods, while keeping the original name.