[FIX] OUTLOOK_AUTH: Fixed emaillog not showing for outlook emails (#959)
This commit is contained in:
@@ -36,16 +36,7 @@ class OutlookBackend(EmailBackend):
|
|||||||
|
|
||||||
def send_messages(self, email_messages):
|
def send_messages(self, email_messages):
|
||||||
response = super().send_messages(email_messages)
|
response = super().send_messages(email_messages)
|
||||||
for message in email_messages:
|
return response
|
||||||
email_log = EmailLog(
|
|
||||||
subject=message.subject,
|
|
||||||
from_email=self.dynamic_from_email_with_display_name,
|
|
||||||
to=message.to,
|
|
||||||
body=message.body,
|
|
||||||
status="sent" if response else "failed",
|
|
||||||
)
|
|
||||||
email_log.save()
|
|
||||||
return
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dynamic_from_email_with_display_name(self):
|
def dynamic_from_email_with_display_name(self):
|
||||||
@@ -168,7 +159,16 @@ def send_mail(self, *args, **kwargs):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.email_data["message"]["attachments"] = outlook_attachments
|
self.email_data["message"]["attachments"] = outlook_attachments
|
||||||
send_outlook_email(self.request, self.email_data)
|
response, _ = send_outlook_email(self.request, self.email_data)
|
||||||
|
|
||||||
|
email_log = EmailLog(
|
||||||
|
subject=self.subject,
|
||||||
|
from_email=self.from_email,
|
||||||
|
to=self.to,
|
||||||
|
body=self.body,
|
||||||
|
status="sent" if response else "failed",
|
||||||
|
)
|
||||||
|
email_log.save()
|
||||||
|
|
||||||
|
|
||||||
EmailMessage.__init__ = __init__
|
EmailMessage.__init__ = __init__
|
||||||
|
|||||||
@@ -153,11 +153,11 @@ def send_outlook_email(request, email_data=None):
|
|||||||
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
|
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
|
||||||
messages.success(request, _("Mail sent"))
|
messages.success(request, _("Mail sent"))
|
||||||
# Email sent successfully!
|
# Email sent successfully!
|
||||||
return email_data
|
return response, email_data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.error(_("Something went wrong"))
|
messages.error(_("Something went wrong"))
|
||||||
messages.info(_("Outlook authentication required/expired"))
|
messages.info(_("Outlook authentication required/expired"))
|
||||||
return email_data
|
return None, email_data
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
Reference in New Issue
Block a user