File size: 1,485 Bytes
17378bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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"