11import mailtrap as mt
2+ from mailtrap .models .mail .batch_mail import BatchSendResponse
23
34API_TOKEN = "<YOUR_API_TOKEN>"
45
@@ -18,8 +19,6 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
1819 return mt .MailtrapClient (
1920 token = API_TOKEN , sandbox = True , inbox_id = "<YOUR_INBOX_ID>"
2021 )
21- else :
22- raise ValueError (f"Invalid sending type: { type_ } " )
2322
2423
2524batch_mail = mt .BatchSendEmailParams (
@@ -31,7 +30,10 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
3130 ),
3231 requests = [
3332 mt .BatchEmailRequest (
34- to = [mt .Address (email = "<RECEIVER_EMAIL>" )],
33+ to = [mt .Address (email = "<RECEIVER_EMAIL_1>" )],
34+ ),
35+ mt .BatchEmailRequest (
36+ to = [mt .Address (email = "<RECEIVER_EMAIL_2>" )],
3537 ),
3638 ],
3739)
@@ -44,6 +46,14 @@ def batch_send(
4446 return client .batch_send (mail )
4547
4648
49+ def batch_send_via_sending_api (
50+ client : mt .MailtrapClient , mail : mt .BaseMail
51+ ) -> BatchSendResponse :
52+ """Another way to batch_send email via Sending API"""
53+ return client .sending_api .batch_send (mail )
54+
55+
4756if __name__ == "__main__" :
4857 client = get_client (SendingType .DEFAULT )
4958 print (batch_send (client , batch_mail ))
59+ print (batch_send_via_sending_api (client , batch_mail ))
0 commit comments