0

I've just implemented django-mailer as it seemed to be the best way to send mail asynchronously from django.

For some reason, django-mailer is creating a db entry for each letter of the recipient's email address, with the "To" field having one letter in it.... Here's a screenshot:

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

I've cut off the rest of the entries so as not to show the full address, but suffice it to say that the "To" fields of all the entries add up to the user's email address. (To clarify, sending one email creates an object for each letter of the email address).

The code which generates the mail is:

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)

Outputting user_email in the notification-email gives the whole email address correctly, so I'm assuming that this is a problem with the django-mailer save function....?

Very grateful for any pointers.

4

1 回答 1

0

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

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

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

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

于 2013-03-21T10:39:37.937 回答