-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbatch_email_send.py
More file actions
51 lines (43 loc) · 1.34 KB
/
batch_email_send.py
File metadata and controls
51 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from typing import List
import resend
import resend.exceptions
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")
params: List[resend.Emails.SendParams] = [
{
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "hey",
"html": "<strong>hello, world!</strong>",
},
{
"from": "[email protected]",
"to": ["[email protected]"],
"subject": "hello",
"html": "<strong>hello, world!</strong>",
},
]
try:
# Send batch emails
print("sending without idempotency_key")
emails: resend.Batch.SendResponse = resend.Batch.send(params)
for email in emails["data"]:
print(f"Email id: {email['id']}")
except resend.exceptions.ResendError as err:
print("Failed to send batch emails")
print(f"Error: {err}")
exit(1)
try:
# Send batch emails with idempotency_key
print("sending with idempotency_key")
options: resend.Batch.SendOptions = {
"idempotency_key": "af477dc78aa9fa91fff3b8c0d4a2e1a5",
}
e: resend.Batch.SendResponse = resend.Batch.send(params, options=options)
for email in e["data"]:
print(f"Email id: {email['id']}")
except resend.exceptions.ResendError as err:
print("Failed to send batch emails")
print(f"Error: {err}")
exit(1)