Spaces:
Runtime error
Runtime error
| from agency_swarm.tools import BaseTool | |
| from pydantic import Field | |
| import os | |
| import requests | |
| import json | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| api_key = os.getenv("MANDRILL_API_KEY") | |
| class SendEmailToSupportTool(BaseTool): | |
| """ | |
| Sends an email to support@jawlat.com.sa using the Mandrill API. | |
| The tool allows setting the subject and body of the email. | |
| """ | |
| subject: str = Field( | |
| ..., description="Subject of the email." | |
| ) | |
| message_body: str = Field( | |
| ..., description="Body content of the email." | |
| ) | |
| def run(self): | |
| """ | |
| Sends an email using the provided subject and body to the fixed support email address. | |
| """ | |
| url = "https://mandrillapp.com/api/1.0/messages/send.json" | |
| headers = {'Content-Type': 'application/json'} | |
| payload = { | |
| "key": api_key, | |
| "message": { | |
| "from_email": "info@jawlat.com.sa", | |
| "to": [ | |
| {"email": "support@jawlat.com.sa", "type": "to"} | |
| ], | |
| "subject": self.subject, | |
| "text": self.message_body | |
| } | |
| } | |
| response = requests.post(url, headers=headers, data=json.dumps(payload)) | |
| if response.status_code == 200: | |
| return "Email successfully sent to support@jawlat.com.sa." | |
| else: | |
| return f"Failed to send email: {response.text}" | |
| return "Result of SendEmailToSupportTool operation" | |