Redmind commited on
Commit
9fb4457
·
verified ·
1 Parent(s): 64bca3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -247,7 +247,7 @@ def document_data_tool(question):
247
  return query_response
248
 
249
 
250
- def send_email_with_attachment(recipient_email, subject, body, attachment_path):
251
  sender_email = os.getenv("EMAIL_SENDER")
252
  sender_password = os.getenv("EMAIL_PASSWORD")
253
 
@@ -259,7 +259,7 @@ def send_email_with_attachment(recipient_email, subject, body, attachment_path):
259
 
260
  # Attach the body with the msg instance
261
  msg.attach(MIMEText(body, 'plain'))
262
-
263
  # Open the file to be sent
264
  attachment = open(attachment_path, "rb")
265
  print("Attached the image")
@@ -275,6 +275,20 @@ def send_email_with_attachment(recipient_email, subject, body, attachment_path):
275
  part.add_header('Content-Disposition', f"attachment; filename= {attachment_path}")
276
 
277
  # Attach the instance 'part' to instance 'msg'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  msg.attach(part)
279
 
280
  # Create SMTP session for sending the mail
@@ -544,8 +558,9 @@ def answer_question(user_question, chatbot, audio=None):
544
  recipient_email=user_email,
545
  subject="Warehouse Inventory Report",
546
  body=response.get("output", "").split(":")[0],
 
547
  # attachment_path=chart_path
548
- attachment_path=os.getenv("IMAGE_PATH")
549
  )
550
 
551
  if "send email to" in user_question:
 
247
  return query_response
248
 
249
 
250
+ def send_email_with_attachment(recipient_email, subject, body, image_data):
251
  sender_email = os.getenv("EMAIL_SENDER")
252
  sender_password = os.getenv("EMAIL_PASSWORD")
253
 
 
259
 
260
  # Attach the body with the msg instance
261
  msg.attach(MIMEText(body, 'plain'))
262
+ """
263
  # Open the file to be sent
264
  attachment = open(attachment_path, "rb")
265
  print("Attached the image")
 
275
  part.add_header('Content-Disposition', f"attachment; filename= {attachment_path}")
276
 
277
  # Attach the instance 'part' to instance 'msg'
278
+ msg.attach(part)"""
279
+ # Create a MIMEBase instance for the attachment
280
+ part = MIMEBase('application', 'octet-stream')
281
+
282
+ # Set the payload with the image data
283
+ part.set_payload(image_data)
284
+
285
+ # Encode the payload into base64
286
+ encoders.encode_base64(part)
287
+
288
+ # Add a header with the filename (you can set any filename you prefer)
289
+ part.add_header('Content-Disposition', 'attachment; filename="image.png"')
290
+
291
+ # Attach the instance 'part' to the instance 'msg'
292
  msg.attach(part)
293
 
294
  # Create SMTP session for sending the mail
 
558
  recipient_email=user_email,
559
  subject="Warehouse Inventory Report",
560
  body=response.get("output", "").split(":")[0],
561
+ image_data = img_str
562
  # attachment_path=chart_path
563
+ #attachment_path=os.getenv("IMAGE_PATH")
564
  )
565
 
566
  if "send email to" in user_question: