-
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
31 additions
and
15 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,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