use only one connection to send multiple mails

v1-0-stable
Christian Merten 9 years ago
parent 171c747492
commit 21994c984c

@ -1,3 +1,4 @@
from django.core import mail
from django.core.mail import EmailMessage
@ -13,8 +14,10 @@ def send(subject, content, sender, recipients, reply_to=None,
kwargs = {"reply_to": [reply_to]}
else:
kwargs = {}
with mail.get_connection() as connection:
for recipient in recipients:
email = EmailMessage(subject, content, sender, [recipient], **kwargs)
email = EmailMessage(subject, content, sender, [recipient],
connection=connection, **kwargs)
if attachments is not None:
for attach in attachments:
email.attach_file(attach)

Loading…
Cancel
Save