【问题标题】:satchmo mail.py send html email instead of text emailsatchmo mail.py 发送 html 电子邮件而不是文本电子邮件
【发布时间】:2012-11-11 09:07:28
【问题描述】:

对于我目前的 satchmo 商店,我想发送 html 电子邮件而不是所有 txt 电子邮件。从 satchmo_store 帐户注册码看,所有的电子邮件都是硬编码的,并且使用 .txt 格式而不是 html 格式。 例如邮件.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 电子邮件的理想方法是什么?

提前致谢。

【问题讨论】:

    标签: python django registration satchmo


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 谢谢,该死。我设法为注册功能创建了 view.py 和 form.py 和 mail.py 的本地副本,并为注册功能添加了 url 的替换,并且运行良好。我想我只需要确保为以后的升级注意这一点,所以我以后必须手动更新本地注册功能。再次感谢。
    猜你喜欢
    • 2017-11-01
    • 2011-09-16
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多