|
|
@@ -1,7 +1,5 @@ |
|
|
from django.core import mail |
|
|
from django.core import mail |
|
|
from django.core.mail import EmailMessage |
|
|
|
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
from django.core.mail.backends.smtp import EmailBackend |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NOT_SENT, SENT, PARTLY_SENT = 0, 1, 2 |
|
|
NOT_SENT, SENT, PARTLY_SENT = 0, 1, 2 |
|
|
@@ -14,20 +12,29 @@ def send_from_arbeitsministerium(subject, content, recipients, reply_to=None): |
|
|
auth_password=settings.EMAIL_ARBEITSMINISTERIUM_PASSWORD) |
|
|
auth_password=settings.EMAIL_ARBEITSMINISTERIUM_PASSWORD) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_from_info(subject, content, recipients, reply_to=None): |
|
|
|
|
|
return send(subject, content, settings.EMAIL_INFO, recipients, |
|
|
|
|
|
reply_to=reply_to, |
|
|
|
|
|
auth_user=settings.EMAIL_INFO_USER, |
|
|
|
|
|
auth_password=settings.EMAIL_INFO_PASSWORD) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send(subject, content, sender, recipients, reply_to=None, |
|
|
def send(subject, content, sender, recipients, reply_to=None, |
|
|
auth_user=None, auth_password=None): |
|
|
auth_user=None, auth_password=None): |
|
|
failed, succeeded = False, False |
|
|
failed, succeeded = False, False |
|
|
if type(recipients) != list: |
|
|
if type(recipients) != list: |
|
|
recipients = [recipients] |
|
|
recipients = [recipients] |
|
|
for recipient in set(recipients): |
|
|
|
|
|
try: |
|
|
|
|
|
mail.send_mail(subject, content, sender, recipients, |
|
|
|
|
|
auth_user=auth_user, |
|
|
|
|
|
auth_password=auth_password) |
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
print("Error when sending mail:", e) |
|
|
|
|
|
failed = True |
|
|
|
|
|
else: |
|
|
|
|
|
succeeded = True |
|
|
|
|
|
|
|
|
with mail.get_connection(username=auth_user, password=auth_password) as conn: |
|
|
|
|
|
for recipient in set(recipients): |
|
|
|
|
|
try: |
|
|
|
|
|
msg = mail.EmailMessage(subject, content, sender, recipients, |
|
|
|
|
|
reply_to=reply_to, |
|
|
|
|
|
connection=conn) |
|
|
|
|
|
msg.send() |
|
|
|
|
|
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 |