-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsending_with_template.py
More file actions
45 lines (34 loc) · 1.33 KB
/
sending_with_template.py
File metadata and controls
45 lines (34 loc) · 1.33 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
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_}")
mail = 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",
},
)
def send(client: mt.MailtrapClient, mail: mt.BaseMail) -> mt.SEND_ENDPOINT_RESPONSE:
return client.send(mail)
if __name__ == "__main__":
client = get_client(SendingType.DEFAULT)
print(send(client, mail))