从 Django 发送 SparkPost 电子邮件时得到 API 结果?
Get API result when sending SparkPost email from Django?
如果我直接通过 SparkPost python API 发送消息,returns 结果如下所示:
{'total_rejected_recipients': 0, 'total_accepted_recipients': 1, 'id': '1234567890'}
Django 内置了通过 sparkpost 发送邮件的集成支持,如果你在 settings.py
中设置 MAIL_BACKEND
:
EMAIL_BACKEND = 'sparkpost.django.email_backend.SparkPostEmailBackend'
SPARKPOST_API_KEY = 'something'
Django 是否提供一种在使用标准 Django 邮件方法时访问 API 结果的方法? (send_mail()
函数或 EmailMessage
class)
Does Django offer a way to access the API result when using the standard Django mail methods? (the send_mail() function or the EmailMessage class)
好像没有。
The source code 显示 SparkPostEmailBackend.send_messages()
获得响应但未将其存储在任何地方:
def send_messages(self, email_messages):
"""
Send emails, returns integer representing number of successful emails
"""
success = 0
for message in email_messages:
try:
response = self._send(SparkPostMessage(message))
success += response['total_accepted_recipients']
except Exception:
if not self.fail_silently:
raise
return success
也许您可以创建从 SparkPostEmailBackend
扩展并覆盖 send_messages()
.
的自定义电子邮件后端
如果我直接通过 SparkPost python API 发送消息,returns 结果如下所示:
{'total_rejected_recipients': 0, 'total_accepted_recipients': 1, 'id': '1234567890'}
Django 内置了通过 sparkpost 发送邮件的集成支持,如果你在 settings.py
中设置 MAIL_BACKEND
:
EMAIL_BACKEND = 'sparkpost.django.email_backend.SparkPostEmailBackend'
SPARKPOST_API_KEY = 'something'
Django 是否提供一种在使用标准 Django 邮件方法时访问 API 结果的方法? (send_mail()
函数或 EmailMessage
class)
Does Django offer a way to access the API result when using the standard Django mail methods? (the send_mail() function or the EmailMessage class)
好像没有。
The source code 显示 SparkPostEmailBackend.send_messages()
获得响应但未将其存储在任何地方:
def send_messages(self, email_messages): """ Send emails, returns integer representing number of successful emails """ success = 0 for message in email_messages: try: response = self._send(SparkPostMessage(message)) success += response['total_accepted_recipients'] except Exception: if not self.fail_silently: raise return success
也许您可以创建从 SparkPostEmailBackend
扩展并覆盖 send_messages()
.