django-mailer从电子邮件地址创建多个数据库条目

时间:2013-03-21 10:20:14

标签: django django-mailer

我刚刚实现了django-mailer,因为它似乎是从django异步发送邮件的最佳方式。

出于某种原因,django-mailer正在为收件人电子邮件地址的每个字母创建一个数据库条目,其中“收件人”字段中包含一个字母....这是截图:

http://i.imgur.com/Pqbx3oq.gif

我已经切断了剩下的条目,以便不显示完整的地址,但只要说所有条目的“收件人”字段加起来就是用户的电子邮件地址就足够了。 (为了澄清,发送一封电子邮件会为电子邮件地址的每个字母创建一个对象)。

生成邮件的代码是:

from mailer import send_mail
from notifications.models import EmailNotifications

users_to_email = EmailNotifications.objects.filter(\
                            product=product)
    if users_to_email:
        for user_to_email in users_to_email:
            the_score = self.rating
            user = user_to_email.user
            name = '%s %s' % (str(user.first_name),\
                                    str(user.last_name))
            user_email = user.email
            theSubject = 'Score Notification'
            theMessage = render_to_string('notification-email.txt',
                                   {'the_score': the_score,
                                    'name': name,
                                    'user': user,
                                    'user_email': user_email})
                send_mail(theSubject, theMessage, SERVER_EMAIL,\
                                                        user_email)

在通知电子邮件中输出user_email会正确显示整个电子邮件地址,所以我假设这是django-mailer保存功能的问题....?

非常感谢任何指示。

1 个答案:

答案 0 :(得分:0)

好的,毕竟,我已经自己解决了,当然,我犯了一个严重的错误......

send_mail需要收件人列表。我本应该做的是:

send_mail(subject, message, SERVER_EMAIL, [user_email])

注意user_email周围的方括号使其成为一个列表......现在一切都很好。

相关问题