-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |