diff --git a/examples/with_attachments.py b/examples/with_attachments.py new file mode 100644 index 0000000..f821161 --- /dev/null +++ b/examples/with_attachments.py @@ -0,0 +1,21 @@ +import os + +from resend import Resend + +if not os.environ["RESEND_API_KEY"]: + raise EnvironmentError("RESEND_API_KEY is missing") + +client = Resend(api_key=os.environ["RESEND_API_KEY"]) + +f = open( + os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb" +).read() + +r = client.send_email( + sender="from@example.io", + to="to@email.com", + subject="hi", + html="hello, world!", + attachments=[{"filename": "invoice.pdf", "content": list(f)}], +) +print(r) diff --git a/resend/api.py b/resend/api.py index 75900a6..8c5d8cd 100644 --- a/resend/api.py +++ b/resend/api.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, List import requests @@ -50,6 +50,7 @@ def send_email( bcc: str = None, cc: str = None, html: str = None, + attachments: List[Dict] = None, ): if not sender: raise ValueError("sender is required.") @@ -71,6 +72,8 @@ def send_email( params["cc"] = cc if bcc: params["bcc"] = bcc + if attachments: + params["attachments"] = attachments resp = self._make_request(url, params, headers) diff --git a/resend/version.py b/resend/version.py index d3ff564..cc76b66 100644 --- a/resend/version.py +++ b/resend/version.py @@ -1,4 +1,4 @@ -__version__ = "0.1.1" +__version__ = "0.2.0" def get_version(): diff --git a/resources/invoice.pdf b/resources/invoice.pdf new file mode 100644 index 0000000..9e7ebca Binary files /dev/null and b/resources/invoice.pdf differ