Bases: Resource
Nylas Transactional Send API.
Send email from a verified domain without a grant context.
Source code in nylas/resources/transactional_send.py
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
65
66
67
68
69
70
71
72
73 | class TransactionalSend(Resource):
"""
Nylas Transactional Send API.
Send email from a verified domain without a grant context.
"""
def send(
self,
domain_name: str,
request_body: TransactionalSendMessageRequest,
overrides: RequestOverrides = None,
) -> Response[Message]:
"""
Send a transactional email from the specified domain.
Args:
domain_name: The domain Nylas sends from (must be verified in the dashboard).
request_body: Message fields; use ``from_`` for the sender (maps to JSON ``from``).
overrides: Per-request overrides for the HTTP client.
Returns:
The sent message in a ``Response``.
"""
path = (
f"/v3/domains/{urllib.parse.quote(domain_name, safe='')}/messages/send"
)
form_data = None
json_body = None
if "from_" in request_body and "from" not in request_body:
request_body["from"] = request_body["from_"]
del request_body["from_"]
attachment_size = sum(
attachment.get("size", 0)
for attachment in request_body.get("attachments", [])
)
if attachment_size >= MAXIMUM_JSON_ATTACHMENT_SIZE:
form_data = _build_form_request(request_body)
else:
for attachment in request_body.get("attachments", []):
if issubclass(type(attachment["content"]), io.IOBase):
attachment["content"] = encode_stream_to_base64(
attachment["content"]
)
json_body = request_body
json_response, headers = self._http_client._execute(
method="POST",
path=path,
request_body=json_body,
data=form_data,
overrides=overrides,
)
return Response.from_dict(json_response, Message, headers)
|
send(domain_name, request_body, overrides=None)
Send a transactional email from the specified domain.
Parameters:
| Name |
Type |
Description |
Default |
domain_name |
str
|
The domain Nylas sends from (must be verified in the dashboard).
|
required
|
request_body |
TransactionalSendMessageRequest
|
Message fields; use from_ for the sender (maps to JSON from).
|
required
|
overrides |
RequestOverrides
|
Per-request overrides for the HTTP client.
|
None
|
Returns:
| Type |
Description |
Response[Message]
|
The sent message in a Response.
|
Source code in nylas/resources/transactional_send.py
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
65
66
67
68
69
70
71
72
73 | def send(
self,
domain_name: str,
request_body: TransactionalSendMessageRequest,
overrides: RequestOverrides = None,
) -> Response[Message]:
"""
Send a transactional email from the specified domain.
Args:
domain_name: The domain Nylas sends from (must be verified in the dashboard).
request_body: Message fields; use ``from_`` for the sender (maps to JSON ``from``).
overrides: Per-request overrides for the HTTP client.
Returns:
The sent message in a ``Response``.
"""
path = (
f"/v3/domains/{urllib.parse.quote(domain_name, safe='')}/messages/send"
)
form_data = None
json_body = None
if "from_" in request_body and "from" not in request_body:
request_body["from"] = request_body["from_"]
del request_body["from_"]
attachment_size = sum(
attachment.get("size", 0)
for attachment in request_body.get("attachments", [])
)
if attachment_size >= MAXIMUM_JSON_ATTACHMENT_SIZE:
form_data = _build_form_request(request_body)
else:
for attachment in request_body.get("attachments", []):
if issubclass(type(attachment["content"]), io.IOBase):
attachment["content"] = encode_stream_to_base64(
attachment["content"]
)
json_body = request_body
json_response, headers = self._http_client._execute(
method="POST",
path=path,
request_body=json_body,
data=form_data,
overrides=overrides,
)
return Response.from_dict(json_response, Message, headers)
|