diff --git a/examples/batch_email_send.py b/examples/batch_email_send.py index e19e7d7..b5e48d0 100644 --- a/examples/batch_email_send.py +++ b/examples/batch_email_send.py @@ -10,13 +10,13 @@ params: List[resend.Emails.SendParams] = [ { "sender": "onboarding@resend.dev", - "to": ["carlosderich@gmail.com"], + "to": ["delivered@resende.dev"], "subject": "hey", "html": "hello, world!", }, { "sender": "onboarding@resend.dev", - "to": ["carlosderich@gmail.com"], + "to": ["delivered@resende.dev"], "subject": "hello", "html": "hello, world!", }, diff --git a/examples/simple_email.py b/examples/simple_email.py index 0ce8dd2..4d90860 100644 --- a/examples/simple_email.py +++ b/examples/simple_email.py @@ -7,7 +7,7 @@ params: resend.Emails.SendParams = { "sender": "onboarding@resend.dev", - "to": ["carlosderich@gmail.com"], + "to": ["delivered@resend.dev"], "subject": "hi", "html": "hello, world!", "reply_to": "to@gmail.com", diff --git a/examples/with_attachments.py b/examples/with_attachments.py index 69caf8b..42aa32f 100644 --- a/examples/with_attachments.py +++ b/examples/with_attachments.py @@ -17,7 +17,7 @@ # Define the email parameters params: resend.Emails.SendParams = { "sender": "onboarding@resend.dev", - "to": ["carlosderich@gmail.com"], + "to": ["delivered@resend.dev"], "subject": "hi", "html": "hello, world!", "attachments": [attachment], diff --git a/examples/with_b64_attachments.py b/examples/with_b64_attachments.py index fd827cb..bab5a4d 100644 --- a/examples/with_b64_attachments.py +++ b/examples/with_b64_attachments.py @@ -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": "onboarding@resend.dev", +# Create attachment object from base64 string +b64_attachment: resend.Attachment = {"filename": "invoice.pdf", "content": b64_str} + +# Email params +params: resend.Emails.SendParams = { + "sender": "onboarding@resend.dev", "to": ["delivered@resend.dev"], "subject": "hello with base64 attachments", "html": "hello, world!", - "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}") diff --git a/examples/with_html_file_as_b64_attachment.py b/examples/with_html_file_as_b64_attachment.py index 882aaf2..94d37f3 100644 --- a/examples/with_html_file_as_b64_attachment.py +++ b/examples/with_html_file_as_b64_attachment.py @@ -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": "onboarding@resend.dev", +# Create attachment object from base64 string +b64_attachment: resend.Attachment = {"filename": "file.html", "content": b64_str} + +# Email params +params: resend.Emails.SendParams = { + "sender": "onboarding@resend.dev", "to": ["delivered@resend.dev"], "subject": "hello with base64 attachments", "html": "hello, world!", - "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) diff --git a/resend/emails/_attachment.py b/resend/emails/_attachment.py index e2b7a5f..90b020c 100644 --- a/resend/emails/_attachment.py +++ b/resend/emails/_attachment.py @@ -1,14 +1,14 @@ -from typing import List +from typing import List, Union from typing_extensions import NotRequired, TypedDict class Attachment(TypedDict): - content: List[int] + content: Union[List[int], str] """ Content of an attached file. This is a list of integers which is usually translated from a - "bytes" type. + "bytes" type, OR a string Ie: list(open("file.pdf", "rb").read()) """ filename: str