|
1 | | -from typing import TYPE_CHECKING, Any, Dict, List, Optional |
| 1 | +from typing import TYPE_CHECKING |
2 | 2 |
|
3 | 3 | from ..utils import validate_email, validate_required_string |
4 | 4 | from .base import BaseResource |
5 | 5 |
|
6 | 6 | if TYPE_CHECKING: |
7 | | - from ..models.email import EmailMessage, EmailSendResponse |
| 7 | + from ..models.email import EmailSendResponse |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class EmailResource(BaseResource): |
@@ -60,151 +60,3 @@ def send_email( |
60 | 60 | from ..models.email import EmailSendResponse |
61 | 61 |
|
62 | 62 | return EmailSendResponse.model_validate(response.json()) |
63 | | - |
64 | | - def send( |
65 | | - self, |
66 | | - to: str, |
67 | | - subject: str, |
68 | | - body: str, |
69 | | - from_: Optional[str] = None, |
70 | | - html_body: Optional[str] = None, |
71 | | - cc: Optional[List[str]] = None, |
72 | | - bcc: Optional[List[str]] = None, |
73 | | - attachments: Optional[List[Dict[str, Any]]] = None, |
74 | | - reply_to: Optional[str] = None, |
75 | | - callback_url: Optional[str] = None, |
76 | | - metadata: Optional[Dict[str, Any]] = None, |
77 | | - ) -> "EmailMessage": |
78 | | - """ |
79 | | - Send an email message. |
80 | | -
|
81 | | - Args: |
82 | | - to: The recipient's email address |
83 | | - subject: The email subject |
84 | | - body: The plain text email body |
85 | | - from_: The sender's email address (optional, uses account default) |
86 | | - html_body: The HTML email body (optional) |
87 | | - cc: List of CC email addresses (optional) |
88 | | - bcc: List of BCC email addresses (optional) |
89 | | - attachments: List of attachment objects (optional) |
90 | | - reply_to: Reply-to email address (optional) |
91 | | - callback_url: Webhook URL for delivery status (optional) |
92 | | - metadata: Custom metadata dictionary (optional) |
93 | | -
|
94 | | - Returns: |
95 | | - EmailMessage: The sent message details |
96 | | - """ |
97 | | - # Validate inputs |
98 | | - to = validate_email(to) |
99 | | - subject = validate_required_string(subject, "subject") |
100 | | - body = validate_required_string(body, "body") |
101 | | - |
102 | | - if from_: |
103 | | - from_ = validate_email(from_) |
104 | | - if reply_to: |
105 | | - reply_to = validate_email(reply_to) |
106 | | - if cc: |
107 | | - cc = [validate_email(email) for email in cc] |
108 | | - if bcc: |
109 | | - bcc = [validate_email(email) for email in bcc] |
110 | | - |
111 | | - # Prepare request data |
112 | | - data = { |
113 | | - "to": to, |
114 | | - "subject": subject, |
115 | | - "body": body, |
116 | | - } |
117 | | - |
118 | | - if from_: |
119 | | - data["from"] = from_ |
120 | | - if html_body: |
121 | | - data["html_body"] = html_body |
122 | | - if cc: |
123 | | - data["cc"] = cc |
124 | | - if bcc: |
125 | | - data["bcc"] = bcc |
126 | | - if attachments: |
127 | | - data["attachments"] = attachments |
128 | | - if reply_to: |
129 | | - data["reply_to"] = reply_to |
130 | | - if callback_url: |
131 | | - data["callback_url"] = callback_url |
132 | | - if metadata: |
133 | | - data["metadata"] = metadata |
134 | | - |
135 | | - # Send request |
136 | | - response = self.client.post("email/messages", json=data) |
137 | | - |
138 | | - from ..models.email import EmailMessage |
139 | | - |
140 | | - return EmailMessage.parse_obj(response.json()) |
141 | | - |
142 | | - def get(self, message_id: str) -> "EmailMessage": |
143 | | - """ |
144 | | - Retrieve an email message by ID. |
145 | | -
|
146 | | - Args: |
147 | | - message_id: The message ID |
148 | | -
|
149 | | - Returns: |
150 | | - EmailMessage: The message details |
151 | | - """ |
152 | | - message_id = validate_required_string(message_id, "message_id") |
153 | | - |
154 | | - response = self.client.get(f"email/messages/{message_id}") |
155 | | - |
156 | | - from ..models.email import EmailMessage |
157 | | - |
158 | | - return EmailMessage.parse_obj(response.json()) |
159 | | - |
160 | | - def list( |
161 | | - self, |
162 | | - to: Optional[str] = None, |
163 | | - from_: Optional[str] = None, |
164 | | - subject: Optional[str] = None, |
165 | | - date_sent_after: Optional[str] = None, |
166 | | - date_sent_before: Optional[str] = None, |
167 | | - status: Optional[str] = None, |
168 | | - limit: int = 50, |
169 | | - offset: int = 0, |
170 | | - ) -> List["EmailMessage"]: |
171 | | - """ |
172 | | - List email messages with optional filtering. |
173 | | -
|
174 | | - Args: |
175 | | - to: Filter by recipient email address |
176 | | - from_: Filter by sender email address |
177 | | - subject: Filter by subject (partial match) |
178 | | - date_sent_after: Filter messages sent after this date |
179 | | - date_sent_before: Filter messages sent before this date |
180 | | - status: Filter by message status |
181 | | - limit: Maximum number of messages to return (default: 50) |
182 | | - offset: Number of messages to skip (default: 0) |
183 | | -
|
184 | | - Returns: |
185 | | - List[EmailMessage]: List of messages |
186 | | - """ |
187 | | - params = { |
188 | | - "limit": limit, |
189 | | - "offset": offset, |
190 | | - } |
191 | | - |
192 | | - if to: |
193 | | - params["to"] = validate_email(to) |
194 | | - if from_: |
195 | | - params["from"] = validate_email(from_) |
196 | | - if subject: |
197 | | - params["subject"] = subject |
198 | | - if date_sent_after: |
199 | | - params["date_sent_after"] = date_sent_after |
200 | | - if date_sent_before: |
201 | | - params["date_sent_before"] = date_sent_before |
202 | | - if status: |
203 | | - params["status"] = status |
204 | | - |
205 | | - response = self.client.get("email/messages", params=params) |
206 | | - data = response.json() |
207 | | - |
208 | | - from ..models.email import EmailMessage |
209 | | - |
210 | | - return [EmailMessage.parse_obj(item) for item in data.get("messages", [])] |
0 commit comments