Skip to content

Commit

Permalink
Merge pull request #13 from resendlabs/feat/add-attachments
Browse files Browse the repository at this point in the history
feat: attachments support
  • Loading branch information
Derich Pacheco authored Apr 26, 2023
2 parents b8d67ae + 891cabf commit 212ae8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions examples/with_attachments.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
to="[email protected]",
subject="hi",
html="<strong>hello, world!</strong>",
attachments=[{"filename": "invoice.pdf", "content": list(f)}],
)
print(r)
5 changes: 4 additions & 1 deletion resend/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, List

import requests

Expand Down Expand Up @@ -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.")
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion resend/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.1"
__version__ = "0.2.0"


def get_version():
Expand Down
Binary file added resources/invoice.pdf
Binary file not shown.

0 comments on commit 212ae8a

Please sign in to comment.