-
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.
Co-authored-by: Pedro Impulcetto <[email protected]>
- Loading branch information
1 parent
544b451
commit 1850c5c
Showing
56 changed files
with
1,431 additions
and
459 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
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,6 +6,7 @@ | |
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) | ||
[![PyPI](https://img.shields.io/pypi/v/resend)](https://pypi.org/project/resend/) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/resend)](https://pypi.org/project/resend) | ||
|
||
--- | ||
|
||
## Installation | ||
|
@@ -29,14 +30,16 @@ resend.api_key = "re_yourkey" | |
|
||
## Example | ||
|
||
You can get an overview about all parameters in the [Send Email](https://resend.com/docs/api-reference/emails/send-email) API reference. | ||
|
||
```py | ||
import os | ||
import resend | ||
|
||
resend.api_key = "re_yourkey" | ||
|
||
params = { | ||
"from": "[email protected]", | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"subject": "hi", | ||
"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
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
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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import os | ||
from typing import List | ||
|
||
import resend | ||
|
||
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
|
||
params = [ | ||
params: List[resend.Emails.SendParams] = [ | ||
{ | ||
"from": "[email protected]", | ||
"to": ["delivered@resend.dev"], | ||
"sender": "[email protected]", | ||
"to": ["delivered@resende.dev"], | ||
"subject": "hey", | ||
"html": "<strong>hello, world!</strong>", | ||
}, | ||
{ | ||
"from": "[email protected]", | ||
"to": ["delivered@resend.dev"], | ||
"sender": "[email protected]", | ||
"to": ["delivered@resende.dev"], | ||
"subject": "hello", | ||
"html": "<strong>hello, world!</strong>", | ||
}, | ||
] | ||
|
||
emails = resend.Batch.send(params) | ||
print(emails) | ||
for email in emails: | ||
print(f"Email sent with 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 |
---|---|---|
|
@@ -5,41 +5,48 @@ | |
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
# replace with some audience id | ||
audience_id: str = "ca4e37c5-a82a-4199-a3b8-bf912a6472aa" | ||
|
||
audience_id = "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e" | ||
|
||
contact = resend.Contacts.create( | ||
{ | ||
"audience_id": audience_id, | ||
"email": "[email protected]", | ||
"first_name": "Steve", | ||
"last_name": "Wozniak", | ||
"unsubscribed": True, | ||
} | ||
) | ||
print("created contact !") | ||
print(contact) | ||
|
||
update_params = { | ||
create_params: resend.Contacts.CreateParams = { | ||
"audience_id": audience_id, | ||
"id": contact["id"], | ||
"last_name": "Updated", | ||
"email": "[email protected]", | ||
"first_name": "Steve", | ||
"last_name": "Wozniak", | ||
"unsubscribed": False, | ||
} | ||
|
||
contact = resend.Contacts.create(create_params) | ||
print(f"Created contact with ID: {contact.id}") | ||
|
||
update_params: resend.Contacts.UpdateParams = { | ||
"audience_id": audience_id, | ||
"id": contact.id, | ||
"unsubscribed": False, | ||
"first_name": "Steve1", | ||
} | ||
|
||
updated = resend.Contacts.update(update_params) | ||
print("updated contact !") | ||
print(updated) | ||
|
||
cont = resend.Contacts.get(audience_id=audience_id, id=contact["id"]) | ||
print(cont) | ||
cont = resend.Contacts.get(audience_id=audience_id, id=contact.id) | ||
print("Retrieved contact") | ||
print(cont.id) | ||
print(cont.email) | ||
print(cont.first_name) | ||
print(cont.last_name) | ||
|
||
contacts = resend.Contacts.list(audience_id=audience_id) | ||
print(contacts) | ||
print("List of contacts") | ||
for contact in contacts: | ||
print( | ||
f"ID: {contact.id}, Email: {contact.email}, First Name: {contact.first_name}, Last Name: {contact.last_name}, Created At: {contact.created_at}, Unsubscribed: {contact.unsubscribed}" | ||
) | ||
|
||
# remove by email | ||
rmed = resend.Contacts.remove(audience_id=audience_id, email="[email protected]") | ||
# rmed = resend.Contacts.remove(audience_id=audience_id, email=cont.email) | ||
|
||
# remove by id | ||
# rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"]) | ||
print(rmed) | ||
rmed = resend.Contacts.remove(audience_id=audience_id, id=cont.id) | ||
print(f"Removed contact - ID: {rmed.id} Deleted: {rmed.deleted}") |
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
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 |
---|---|---|
|
@@ -5,9 +5,8 @@ | |
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
|
||
params = { | ||
"from": "[email protected]", | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"subject": "hi", | ||
"html": "<strong>hello, world!</strong>", | ||
|
@@ -21,7 +20,8 @@ | |
} | ||
|
||
email = resend.Emails.send(params) | ||
print(email) | ||
print(f"Email sent with id: {email.id}") | ||
|
||
email_resp = resend.Emails.get(email_id=email["id"]) | ||
print(email_resp) | ||
email_resp = resend.Emails.get(email_id=email.id) | ||
print(f"Retrieved email: {email_resp.id}") | ||
print(email_resp.__dict__) |
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,17 +6,23 @@ | |
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
|
||
f = open( | ||
# Read file | ||
f: bytes = open( | ||
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb" | ||
).read() | ||
|
||
params = { | ||
"from": "[email protected]", | ||
"to": "[email protected]", | ||
# Define the file attachment | ||
attachment: resend.Attachment = {"filename": "invoice.pdf", "content": list(f)} | ||
|
||
# Define the email parameters | ||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["[email protected]"], | ||
"subject": "hi", | ||
"html": "<strong>hello, world!</strong>", | ||
"attachments": [{"filename": "invoice.pdf", "content": list(f)}], | ||
"attachments": [attachment], | ||
} | ||
|
||
r = resend.Emails.send(params) | ||
print(r) | ||
print("Sent email with attachment") | ||
print(f"Email ID: {r.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/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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
import resend | ||
|
||
if not os.environ["RESEND_API_KEY"]: | ||
raise EnvironmentError("RESEND_API_KEY is missing") | ||
|
||
params: resend.Emails.SendParams = { | ||
"sender": "[email protected]", | ||
"to": ["invalid"], | ||
"subject": "hi", | ||
"html": "<strong>hello, world!</strong>", | ||
} | ||
|
||
try: | ||
email = resend.Emails.send(params) | ||
except resend.exceptions.ResendError as e: | ||
print(f"Error sending email: {e}") |
Oops, something went wrong.