4

我正在试验 Django 的 mass_mail 功能。下面的代码不断引发“Too Many Values to Unpack”错误,我不知道为什么。我正在关注看起来很简单的文档(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)
4

1 回答 1

6

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

send_mass_mail((mail_tuple,))
于 2013-08-15T20:53:12.080 回答