Skip to content

Commit

Permalink
fix: attachment types fix (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
drish authored Apr 22, 2024
1 parent 7245692 commit b2357af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
18 changes: 12 additions & 6 deletions examples/with_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
raise EnvironmentError("RESEND_API_KEY is missing")


f = open(
# Read file
f: bytes = open(
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb"
).read()

params = {
"from": "[email protected]",
"to": "[email protected]",
# Define the file attachment
attachment: resend.Attachment = {"filename": "invoice.pdf", "content": list(f)}

# Define the email parameters
params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["[email protected]"],
"subject": "hi",
"html": "<strong>hello, world!</strong>",
"attachments": [{"filename": "invoice.pdf", "content": list(f)}],
"attachments": [attachment],
}

r = resend.Emails.send(params)
print(r)
print("Sent email with attachment")
print(f"Email ID: {r.id}")
5 changes: 5 additions & 0 deletions resend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from .audiences._audiences import Audiences
from .contacts._contacts import Contacts
from .domains._domains import Domains
from .emails._attachment import Attachment
from .emails._batch import Batch
from .emails._emails import Emails
from .emails._tag import Tag
from .request import Request
from .version import get_version

Expand All @@ -25,4 +27,7 @@
"Batch",
"Audiences",
"Contacts",
# Types
"Attachment",
"Tag",
]
11 changes: 8 additions & 3 deletions resend/emails/_attachment.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
from typing_extensions import TypedDict
from typing import List

from typing_extensions import NotRequired, TypedDict


class Attachment(TypedDict):
content: str
content: List[int]
"""
Content of an attached file.
This is a list of integers which is usually translated from a
"bytes" type.
Ie: list(open("file.pdf", "rb").read())
"""
filename: str
"""
Name of attached file.
"""
path: str
path: NotRequired[str]
"""
Path where the attachment file is hosted
"""

0 comments on commit b2357af

Please sign in to comment.