-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsending.py
More file actions
83 lines (70 loc) · 2.69 KB
/
sending.py
File metadata and controls
83 lines (70 loc) · 2.69 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import mailtrap as mt
API_TOKEN = "<YOUR_API_TOKEN>"
INBOX_ID = "<YOUR_INBOX_ID>"
default_client = mt.MailtrapClient(token=API_TOKEN)
bulk_client = mt.MailtrapClient(token=API_TOKEN, bulk=True)
sandbox_client = mt.MailtrapClient(token=API_TOKEN, sandbox=True, inbox_id=INBOX_ID)
mail = mt.Mail(
sender=mt.Address(email="<SENDER_EMAIL>", name="<SENDER_NAME>"),
to=[mt.Address(email="<RECEIVER_EMAIL>")],
subject="You are awesome!",
text="Congrats for sending test email with Mailtrap!",
category="Integration Test",
)
mail_from_template = mt.MailFromTemplate(
sender=mt.Address(email="<SENDER_EMAIL>", name="<SENDER_NAME>"),
to=[mt.Address(email="<RECEIVER_EMAIL>")],
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",
},
)
batch_mail = mt.BatchSendEmailParams(
base=mt.BatchMail(
sender=mt.Address(email="<SENDER_EMAIL>", name="<SENDER_NAME>"),
subject="You are awesome!",
text="Congrats for sending test email with Mailtrap!",
category="Integration Test",
),
requests=[
mt.BatchEmailRequest(
to=[mt.Address(email="<RECEIVER_EMAIL>")],
),
],
)
batch_mail_from_template = 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>")],
subject="You are awesome!",
text="Congrats for sending test email with Mailtrap!",
category="Integration Test",
),
],
)
def send(client: mt.MailtrapClient, mail: mt.BaseMail) -> mt.SEND_ENDPOINT_RESPONSE:
return client.send(mail)
def batch_send(
client: mt.MailtrapClient, mail: mt.BatchSendEmailParams
) -> mt.BATCH_SEND_ENDPOINT_RESPONSE:
return client.batch_send(mail=mail)
if __name__ == "__main__":
print(send(default_client, mail))
print(batch_send(default_client, batch_mail))