Skip to content

Commit

Permalink
changes and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
spandan_mondal committed Dec 9, 2024
1 parent d075337 commit 97752a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions kairon/shared/channels/mail/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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):
Expand Down

0 comments on commit 97752a2

Please sign in to comment.