from mailjet_rest import Client import base64 import pandas as pd from io import BytesIO import datetime class Mail(): def __init__(self, api_key, api_secret): self.api_key = api_key self.api_secret = api_secret self.mailjet = Client(auth=(self.api_key, self.api_secret), version='v3.1') def send_mail(self, fromName, fromMail, fromSubject, fromMsg, dataframe, forecast_dates, toMail): Subject = 'Predictions are ready! - Infineon Product Demand Forecasting System' TextPart = f'Greetings from {Subject}' with BytesIO() as output: with pd.ExcelWriter(output, engine='xlsxwriter') as writer: dataframe.to_excel(writer, sheet_name='Sheet1', index=False) output.seek(0) excel_content = output.read() # Encode Excel content to base64 base64_content = base64.b64encode(excel_content).decode() today = datetime.datetime.today().strftime("%d-%m-%Y") data = { 'Messages': [ { "From": { "Email": "alper.tml.14@hotmail.com", "Name": "Me" }, "To": [ { "Email": toMail, "Name": "You" } ], "Subject": Subject, "TextPart": TextPart, "HTMLPart": f"Hello,

You can access the demand forecasting output for Infenion for the following dates {forecast_dates[0]} - {forecast_dates[1]} in the attachments
If you have any problems, you can let us know via this e-mail address.

Have a good day,

Infineon AI Department

", 'Attachments': [ { 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Filename': f'demand_predictions_{today}.xlsx', 'Base64Content': base64_content } ] } ] } result = self.mailjet.send.create(data=data) return result.status_code