[FIX] OUTLOOK: Fixed emaillog not showing for outlook emails
This commit is contained in:
@@ -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__
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user