-
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.
examples: fix types on examples with attachments (#77)
- Loading branch information
Showing
6 changed files
with
35 additions
and
19 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 |
---|---|---|
|
@@ -10,13 +10,13 @@ | |
params: List[resend.Emails.SendParams] = [ | ||
{ | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"to": ["[email protected]"], | ||
"subject": "hey", | ||
"html": "<strong>hello, world!</strong>", | ||
}, | ||
{ | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"to": ["[email protected]"], | ||
"subject": "hello", | ||
"html": "<strong>hello, world!</strong>", | ||
}, | ||
|
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"to": ["[email protected]"], | ||
"subject": "hi", | ||
"html": "<strong>hello, world!</strong>", | ||
"reply_to": "[email protected]", | ||
|
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
# Define the email parameters | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"to": ["[email protected]"], | ||
"subject": "hi", | ||
"html": "<strong>hello, world!</strong>", | ||
"attachments": [attachment], | ||
|
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,20 +6,28 @@ | |
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
# Read file | ||
f = open( | ||
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb" | ||
).read() | ||
|
||
b64 = base64.b64encode(f) | ||
b64_str = b64.decode("utf-8") | ||
# Read file bytes as a base64 string | ||
b64: bytes = base64.b64encode(f) | ||
b64_str: str = b64.decode("utf-8") | ||
|
||
params = { | ||
"from": "[email protected]", | ||
# Create attachment object from base64 string | ||
b64_attachment: resend.Attachment = {"filename": "invoice.pdf", "content": b64_str} | ||
|
||
# Email params | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"subject": "hello with base64 attachments", | ||
"html": "<strong>hello, world!</strong>", | ||
"attachments": [{"filename": "invoice.pdf", "content": b64_str}], | ||
"attachments": [b64_attachment], | ||
} | ||
|
||
# Send email | ||
email = resend.Emails.send(params) | ||
print(email) | ||
print("Email sent with base64 string attachment") | ||
print(f"Email ID: {email.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,20 +6,28 @@ | |
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
# Read file | ||
f = open( | ||
os.path.join(os.path.dirname(__file__), "../resources/index.html"), "rb" | ||
).read() | ||
|
||
b64 = base64.b64encode(f) | ||
b64_str = b64.decode("utf-8") | ||
# Read file bytes as a base64 string | ||
b64: bytes = base64.b64encode(f) | ||
b64_str: str = b64.decode("utf-8") | ||
|
||
params = { | ||
"from": "[email protected]", | ||
# Create attachment object from base64 string | ||
b64_attachment: resend.Attachment = {"filename": "file.html", "content": b64_str} | ||
|
||
# Email params | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"subject": "hello with base64 attachments", | ||
"html": "<strong>hello, world!</strong>", | ||
"attachments": [{"filename": "file.html", "content": b64_str}], | ||
"attachments": [b64_attachment], | ||
} | ||
|
||
# Send email | ||
email = resend.Emails.send(params) | ||
print(email) | ||
print("Sent email with base64 string attachment") | ||
print("Email ID: ", email.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