gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:09:26 25 4
gpt4 key购买 nike

对于我当前的 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 电子邮件的理想方法是什么?

提前致谢。

最佳答案

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

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

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

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

关于python - satchmo mail.py 发送 html 电子邮件而不是文本电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13521655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com