[FIX] OUTLOOK_AUTH: Fixed emaillog not showing for outlook emails (#959)

This commit is contained in:
Horilla
2025-11-07 14:09:45 +05:30
parent bed1d69e3d
commit 94516ef78e
2 changed files with 13 additions and 13 deletions

View File

@@ -36,16 +36,7 @@ class OutlookBackend(EmailBackend):
def send_messages(self, email_messages):
response = super().send_messages(email_messages)
for message in email_messages:
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
return response
@property
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
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__

View File

@@ -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)
messages.success(request, _("Mail sent"))
# Email sent successfully!
return email_data
return response, email_data
except Exception as e:
messages.error(_("Something went wrong"))
messages.info(_("Outlook authentication required/expired"))
return email_data
return None, email_data
@login_required