satchmo mail.py发送html电子邮件而不是文本电子邮件

时间:2012-11-23 00:16:09

标签: python django registration satchmo

对于我目前的satchmo商店,我想发送html电子邮件而不是所有的txt电子邮件。通过satchmo_store帐户注册码的外观,所有电子邮件都是硬编码的,并使用.txt格式而不是html格式。 例如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)

我知道您可以将最后一行更改为以下内容以使其正常工作:

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')

但是,最好不要在不久的将来触及Satchmo应用程序中的代码以进行升级。

有没有人知道在不触及satchmo应用程序的情况下覆盖此功能或为所有注册相关功能启用html电子邮件的理想方法是什么?

提前致谢。

1 个答案:

答案 0 :(得分:1)

我通过以下方式对Satchmo内部进行了类似的更改:

应该可以将Satchmo安装中的相关文件复制到django应用程序中。如果您根据this recommendation设置Satchmo商店,则可能意味着将satchmo / apps / satchmo_store / accounts / mail.py复制到/localsite/accounts/mail.py。我们的想法是自动加载本地副本而不是原始副本。

在mail.py的本地副本中,您可以替换send_store_email()函数。记下备注,以便在Satchmo升级时记住您的更改。原始文件很可能仍然是相同的,并且即使对于将来的版本,您的覆盖也会起作用。

在其他情况下,当您必须更改某些类行为时,您还可以将原始类子类化,只更改相关方法,同时保留原始名称。