Skip to content

Commit 2335a83

Browse files
committed
feat: support for remote path
1 parent ea33238 commit 2335a83

4 files changed

Lines changed: 48 additions & 14 deletions

File tree

examples/with_inline_attachments.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,42 @@
1010
"rb",
1111
).read()
1212

13-
# Define the file attachment
14-
attachment: resend.Attachment = {
13+
# Send email with local inline attachment
14+
local_attachment: resend.Attachment = {
1515
"filename": "resend-wordmark-black.png",
1616
"content": list(f),
1717
"content_type": "image/png",
1818
# This is the content ID that will be used in the HTML to reference the image
1919
"inline_content_id": "my-test-image",
2020
}
2121

22-
# Define the email parameters
23-
params: resend.Emails.SendParams = {
22+
local_params: resend.Emails.SendParams = {
2423
"from": "onboarding@resend.dev",
2524
"to": ["delivered@resend.dev"],
26-
"subject": "Inline attachment test from Resend's python SDK",
27-
"html": '<p>This is an email with an <img width=100 height=40 src="cid:my-test-image" /> embed image</p>',
28-
"attachments": [attachment],
25+
"subject": "Local inline attachment test from Resend's python SDK",
26+
"html": '<p>This email contains a local inline attachment: <img width=100 height=40 src="cid:my-test-image" /></p>',
27+
"attachments": [local_attachment],
2928
}
3029

31-
email: resend.Email = resend.Emails.send(params)
32-
print("Sent email with attachment")
33-
print(email)
30+
local_email: resend.Email = resend.Emails.send(local_params)
31+
print("Sent email with local inline attachment")
32+
print(local_email)
33+
34+
# Send email with remote inline attachment
35+
remote_attachment: resend.RemoteAttachment = {
36+
"filename": "remote-resend-wordmark-black.png",
37+
"path": "https://resend.com/static/brand/resend-wordmark-black.png",
38+
"inline_content_id": "my-test-image",
39+
}
40+
41+
remote_params: resend.Emails.SendParams = {
42+
"from": "onboarding@resend.dev",
43+
"to": ["delivered@resend.dev"],
44+
"subject": "Remote inline attachment test from Resend's python SDK",
45+
"html": '<p>This email contains a remote inline attachment: <img width=100 height=40 src="cid:my-test-image" /></p>',
46+
"attachments": [remote_attachment],
47+
}
48+
49+
remote_email: resend.Email = resend.Emails.send(remote_params)
50+
print("Sent email with remote inline attachment")
51+
print(remote_email)

resend/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .contacts._contacts import Contacts
1111
from .domains._domain import Domain
1212
from .domains._domains import Domains
13-
from .emails._attachment import Attachment
13+
from .emails._attachment import Attachment, RemoteAttachment
1414
from .emails._batch import Batch
1515
from .emails._email import Email
1616
from .emails._emails import Emails
@@ -48,6 +48,7 @@
4848
"ApiKey",
4949
"Email",
5050
"Attachment",
51+
"RemoteAttachment",
5152
"Tag",
5253
"Broadcast",
5354
# Default HTTP Client

resend/emails/_attachment.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ class Attachment(TypedDict):
2727
"""
2828
Content ID for inline attachments used in HTML content with cid: references
2929
"""
30+
31+
32+
class RemoteAttachment(TypedDict):
33+
path: str
34+
"""
35+
Path where the remote attachment file is hosted
36+
"""
37+
filename: NotRequired[str]
38+
"""
39+
Name of attached file.
40+
"""
41+
inline_content_id: NotRequired[str]
42+
"""
43+
Content ID for inline attachments used in HTML content with cid: references
44+
"""

resend/emails/_emails.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing_extensions import NotRequired, TypedDict
44

55
from resend import request
6-
from resend.emails._attachment import Attachment
6+
from resend.emails._attachment import Attachment, RemoteAttachment
77
from resend.emails._email import Email
88
from resend.emails._tag import Tag
99

@@ -95,7 +95,7 @@ class _SendParamsDefault(_SendParamsFrom):
9595
"""
9696
Custom headers to be added to the email.
9797
"""
98-
attachments: NotRequired[List[Attachment]]
98+
attachments: NotRequired[List[Union[Attachment, RemoteAttachment]]]
9999
"""
100100
List of attachments to be added to the email.
101101
"""
@@ -153,7 +153,7 @@ class SendParams(_SendParamsDefault):
153153
html (NotRequired[str]): The HTML content of the email.
154154
text (NotRequired[str]): The text content of the email.
155155
headers (NotRequired[Dict[str, str]]): Custom headers to be added to the email.
156-
attachments (NotRequired[List[Attachment]]): List of attachments to be added to the email.
156+
attachments (NotRequired[List[Union[Attachment, RemoteAttachment]]]): List of attachments to be added to the email.
157157
tags (NotRequired[List[Tag]]): List of tags to be added to the email.
158158
"""
159159

0 commit comments

Comments
 (0)