-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbatch_sending_with_template.py
More file actions
57 lines (46 loc) · 1.63 KB
/
batch_sending_with_template.py
File metadata and controls
57 lines (46 loc) · 1.63 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
52
53
54
55
56
57
import mailtrap as mt
API_TOKEN = "<YOUR_API_TOKEN>"
class SendingType:
DEFAULT = "default"
BULK = "bulk"
SANDBOX = "sandbox"
def get_client(type_: SendingType) -> mt.MailtrapClient:
if type_ == SendingType.DEFAULT:
return mt.MailtrapClient(token=API_TOKEN)
elif type_ == SendingType.BULK:
return mt.MailtrapClient(token=API_TOKEN, bulk=True)
elif type_ == SendingType.SANDBOX:
return mt.MailtrapClient(
token=API_TOKEN, sandbox=True, inbox_id="<YOUR_INBOX_ID>"
)
raise ValueError(f"Invalid sending type: {type_}")
batch_mail = mt.BatchSendEmailParams(
base=mt.BatchMailFromTemplate(
sender=mt.Address(email="<SENDER_EMAIL>", name="<SENDER_NAME>"),
template_uuid="<YOUR_TEMPLATE_UUID>",
template_variables={
"company_info_name": "Test_Company_info_name",
"name": "Test_Name",
"company_info_address": "Test_Company_info_address",
"company_info_city": "Test_Company_info_city",
"company_info_zip_code": "Test_Company_info_zip_code",
"company_info_country": "Test_Company_info_country",
},
),
requests=[
mt.BatchEmailRequest(
to=[mt.Address(email="<RECEIVER_EMAIL_1>")],
),
mt.BatchEmailRequest(
to=[mt.Address(email="<RECEIVER_EMAIL_2>")],
),
],
)
def batch_send(
client: mt.MailtrapClient,
mail: mt.BatchSendEmailParams,
) -> mt.BATCH_SEND_ENDPOINT_RESPONSE:
return client.batch_send(mail)
if __name__ == "__main__":
client = get_client(SendingType.DEFAULT)
print(batch_send(client, batch_mail))