-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.py
More file actions
64 lines (52 loc) · 1.83 KB
/
email.py
File metadata and controls
64 lines (52 loc) · 1.83 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from typing import TYPE_CHECKING
from ..utils import validate_email, validate_required_string
from .base import BaseResource
if TYPE_CHECKING:
from ..models.email import EmailSendResponse
class EmailResource(BaseResource):
"""
Email resource for sending and managing email messages.
Example:
>>> response = client.email.send_email(
... subject="Hello, World!",
... body="This is a test email.",
... sender="sender@example.com",
... recipient="recipient@example.com"
... )
>>> print(response.message_id)
"""
def send_email(
self,
subject: str,
body: str,
sender: str,
recipient: str,
sandbox: bool = False,
) -> "EmailSendResponse":
"""
Send an email using the exact API specification.
Args:
subject: Email subject
body: Email body content
sender: Sender email address
recipient: Recipient email address
sandbox: Use sandbox environment for testing (default: False)
Returns:
EmailSendResponse: The email send response
"""
# Validate inputs
subject = validate_required_string(subject, "subject")
body = validate_required_string(body, "body")
sender = validate_email(sender)
recipient = validate_email(recipient)
# Prepare request data matching the exact API specification
data = {
"subject": subject,
"body": body,
"sender": sender,
"recipient": recipient,
}
# Send request to the exact endpoint
response = self.client.post("user-api/email/send", json=data)
from ..models.email import EmailSendResponse
return EmailSendResponse.model_validate(response.json())