|
|
|
@ -20,21 +20,27 @@ def send(subject, content, sender, recipients, message_id=None, reply_to=None,
|
|
|
|
headers = {'Message-ID': message_id}
|
|
|
|
headers = {'Message-ID': message_id}
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
headers = {}
|
|
|
|
headers = {}
|
|
|
|
with mail.get_connection() as connection:
|
|
|
|
|
|
|
|
for recipient in set(recipients):
|
|
|
|
# construct mails
|
|
|
|
email = EmailMessage(subject, content, sender, [recipient],
|
|
|
|
mails = []
|
|
|
|
headers=headers,
|
|
|
|
for recipient in set(recipients):
|
|
|
|
connection=connection, **kwargs)
|
|
|
|
email = EmailMessage(subject, content, sender, [recipient],
|
|
|
|
if attachments is not None:
|
|
|
|
headers=headers, **kwargs)
|
|
|
|
for attach in attachments:
|
|
|
|
if attachments is not None:
|
|
|
|
email.attach_file(attach)
|
|
|
|
for attach in attachments:
|
|
|
|
try:
|
|
|
|
email.attach_file(attach)
|
|
|
|
email.send(fail_silently=True)
|
|
|
|
mails.append(email)
|
|
|
|
except Exception as e:
|
|
|
|
try:
|
|
|
|
print("Error when sending mail:", e)
|
|
|
|
# connect to smtp server
|
|
|
|
failed = True
|
|
|
|
connection = mail.get_connection()
|
|
|
|
else:
|
|
|
|
# send all mails with one connection
|
|
|
|
succeeded = True
|
|
|
|
connection.send_messages(mails)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
print("Error when sending mail:", e)
|
|
|
|
|
|
|
|
failed = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
succeeded = True
|
|
|
|
|
|
|
|
|
|
|
|
return NOT_SENT if failed and not succeeded else SENT if not failed\
|
|
|
|
return NOT_SENT if failed and not succeeded else SENT if not failed\
|
|
|
|
and succeeded else PARTLY_SENT
|
|
|
|
and succeeded else PARTLY_SENT
|
|
|
|
|
|
|
|
|
|
|
|
|