python - 在 Django 中发送群发邮件——太多的值无法解压

标签 python django

我正在试验 Django 的群发邮件功能。下面的代码不断引发“要解包的值太多”错误,我不明白为什么。我正在关注看起来非常简单的文档 ( https://docs.djangoproject.com/en/1.5/topics/email/#send-mass-mail)——我做错了什么?如果重要的话,发送电子邮件地址是编造的,但我认为这无关紧要。

if matching_record.level == 1:
                users = self._get_users_to_be_notified(matching_record.category)
                email_recipients = [str(user.email) for user in users if user.email]
                message = 'Here is your requested notification that the service "%s" is having technical difficulties and has been set to "Critical".' %matching_record.name
                mail_tuple = ('Notification', 
                              message, 
                              'notifications@service.com', 
                              email_recipients)
                send_mass_mail(mail_tuple)

最佳答案

send_mass_mail 方法的第一个参数是一个消息元组的元组,但您发送的只是一个消息元组。像下面这样更改函数调用并检查它是否有效:

send_mass_mail((mail_tuple,))

关于python - 在 Django 中发送群发邮件——太多的值无法解压,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18261478/

相关文章:

python - 确定递归算法的计算复杂度

python - 关系 "social_auth_usersocialauth"不存在。迁移不会创建这些表

html - Django 模板上的 URL 编码

python - 将 SQLAlchemy 对象转换为 Python 字典的快速方法

python - 在 Python 中实现一种特殊类型的多处理队列

Python scrapy 持久数据库连接 MySQL

python - SQLalchemy/Flask - 一对一嵌套

python - 如何统计有多少条记录在字段中具有最小值? ( Django )

django - 如何将 Django 信号与抽象模型一起使用?

python - 将上下文传递到 django 管理索引页面