From 97752a228f94714ab7ae85269ff7e5faea0f0737 Mon Sep 17 00:00:00 2001 From: spandan_mondal Date: Mon, 9 Dec 2024 13:16:58 +0530 Subject: [PATCH] changes and test cases --- kairon/shared/channels/mail/processor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kairon/shared/channels/mail/processor.py b/kairon/shared/channels/mail/processor.py index 09f4e1a7b..f68f286bb 100644 --- a/kairon/shared/channels/mail/processor.py +++ b/kairon/shared/channels/mail/processor.py @@ -103,6 +103,7 @@ def validate_imap_connection(bot): return False async def send_mail(self, to: str, subject: str, body: str, log_id: str): + exception = None try: if body and len(body) > 0: email_account = self.config['email_account'] @@ -112,14 +113,14 @@ async def send_mail(self, to: str, subject: str, body: str, log_id: str): msg['Subject'] = subject msg.attach(MIMEText(body, 'html')) self.smtp.sendmail(email_account, to, msg.as_string()) - mail_log = MailResponseLog.objects.get(id=log_id) - mail_log.status = MailStatus.SUCCESS.value - mail_log.save() except Exception as e: logger.error(f"Error sending mail to {to}: {str(e)}") + exception = str(e) + finally: mail_log = MailResponseLog.objects.get(id=log_id) - mail_log.status = MailStatus.FAILED.value - mail_log.responses.append(str(e)) + mail_log.status = MailStatus.FAILED.value if exception else MailStatus.SUCCESS.value + if exception: + mail_log.responses.append(exception) mail_log.save() def process_mail(self, rasa_chat_response: dict, log_id: str):