我刚刚实现了django-mailer,因为它似乎是从django异步发送邮件的最佳方式。
由于某些原因,django-mailer正在为收件人的电子邮件地址的每个字母创建一个数据库条目,"To“字段中有一个字母。这是一个截图:
http://i.imgur.com/Pqbx3oq.gif
我去掉了其余的条目,这样就不会显示完整的地址,但可以说,所有条目的" to“字段加起来就是用户的电子邮件地址。(为了清楚起见,发送一封电子邮件会为电子邮件地址的每个字母创建一个对象)。
生成邮件的代码是:
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保存功能的问题……?
非常感谢您的指点。
发布于 2013-03-21 18:39:38
好了,在这之后,我自己解决了这个问题,当然,我犯了一个严重的n00b错误……
send_mail需要收件人列表。我应该做的是:
send_mail(subject, message, SERVER_EMAIL, [user_email])请注意user_email周围的方括号,使其成为列表.....现在一切都很好。
https://stackoverflow.com/questions/15544748
复制相似问题