Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion examples/contacts/contact_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ def delete_contact_field(contact_field_id: int) -> DeletedObject:


if __name__ == "__main__":
print(list_contact_fields())
created = create_contact_field(
name="example_field", data_type="string", merge_tag="EXAMPLE"
)
print(created)

fields = list_contact_fields()
print(fields)

field = get_contact_field(contact_field_id=created.id)
print(field)

updated = update_contact_field(
contact_field_id=created.id, name=f"{field.name}-updated"
)
print(updated)

deleted = delete_contact_field(contact_field_id=created.id)
print(deleted)
18 changes: 17 additions & 1 deletion examples/contacts/contact_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ def delete_contact_list(contact_list_id: int) -> DeletedObject:


if __name__ == "__main__":
print(list_contact_lists())
created = create_contact_list(name="example-list")
print(created)

lists = list_contact_lists()
print(lists)

contact_list = get_contact_list(contact_list_id=created.id)
print(contact_list)

updated = update_contact_list(
contact_list_id=created.id,
name=f"{contact_list.name}-updated",
)
print(updated)

deleted = delete_contact_list(contact_list_id=created.id)
print(deleted)
5 changes: 5 additions & 0 deletions examples/contacts/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def delete_contact(contact_id_or_email: str) -> DeletedObject:
},
)
print(created_contact)

updated_contact = update_contact(
created_contact.id,
fields={
Expand All @@ -68,5 +69,9 @@ def delete_contact(contact_id_or_email: str) -> DeletedObject:
},
)
print(updated_contact)

contact = get_contact(updated_contact.id)
print(contact)

deleted_contact = delete_contact(updated_contact.id)
print(deleted_contact)
31 changes: 27 additions & 4 deletions examples/email_templates/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def create_template(
return templates_api.create(params)


def get_template(template_id: str) -> EmailTemplate:
def get_template(template_id: int) -> EmailTemplate:
return templates_api.get_by_id(template_id)


def update_template(
template_id: str,
template_id: int,
name: Optional[str] = None,
subject: Optional[str] = None,
category: Optional[str] = None,
Expand All @@ -54,9 +54,32 @@ def update_template(
return templates_api.update(template_id, params)


def delete_template(template_id: str) -> DeletedObject:
def delete_template(template_id: int) -> DeletedObject:
return templates_api.delete(template_id)


if __name__ == "__main__":
print(list_templates())
created = create_template(
name="Example Template",
subject="Hello",
category="transactional",
body_text="Hello world",
)
print(created)

templates = list_templates()
print(templates)

template = get_template(template_id=created.id)
print(template)

updated = update_template(
template_id=created.id,
name=f"{template.name}-updated",
subject=f"{template.subject}-updated",
body_text=f"{template.body_text}\nUpdated content.",
)
print(updated)

deleted = delete_template(template_id=created.id)
print(deleted)
9 changes: 8 additions & 1 deletion examples/general/account_accesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ def delete_account_access(account_id: int, account_access_id: int) -> DeletedObj


if __name__ == "__main__":
print(get_account_accesses(ACCOUNT_ID))
accesses = get_account_accesses(ACCOUNT_ID)
print(accesses)
if accesses:
access_id = accesses[0].id
deleted = delete_account_access(
account_id=ACCOUNT_ID, account_access_id=access_id
)
print(deleted)
3 changes: 2 additions & 1 deletion examples/general/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ def get_accounts() -> list[Account]:


if __name__ == "__main__":
print(get_accounts())
accounts = get_accounts()
print(accounts)
3 changes: 2 additions & 1 deletion examples/general/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ def get_current_billing_usage(account_id: int) -> BillingCycleUsage:


if __name__ == "__main__":
print(get_current_billing_usage(ACCOUNT_ID))
usage = get_current_billing_usage(ACCOUNT_ID)
print(usage)
18 changes: 17 additions & 1 deletion examples/general/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ def bulk_permissions_update(


if __name__ == "__main__":
print(get_permission_resources(ACCOUNT_ID))
resources = get_permission_resources(ACCOUNT_ID)
print(resources)
if resources:
account_access_id = resources[0].id
permissions = [
mt.PermissionResourceParams(
resource_id=resources[0].id,
resource_type=resources[0].type,
access_level="viewer",
)
]
updated = bulk_permissions_update(
ACCOUNT_ID,
account_access_id,
permissions,
)
print(updated)
1 change: 1 addition & 0 deletions examples/sending/advanced_sending.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
sandbox=True,
inbox_id="<YOUR_INBOX_ID>",
)
raise ValueError(f"Invalid sending type: {type_}")


# Image should be in the same level in directory like this python file.
Expand Down
1 change: 1 addition & 0 deletions examples/sending/batch_advanced_sending.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
sandbox=True,
inbox_id="<YOUR_INBOX_ID>",
)
raise ValueError(f"Invalid sending type: {type_}")


# Image should be in the same level in directory like this python file.
Expand Down
1 change: 1 addition & 0 deletions examples/sending/batch_minimal_sending.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
return mt.MailtrapClient(
token=API_TOKEN, sandbox=True, inbox_id="<YOUR_INBOX_ID>"
)
raise ValueError(f"Invalid sending type: {type_}")


batch_mail = mt.BatchSendEmailParams(
Expand Down
1 change: 1 addition & 0 deletions examples/sending/batch_sending_with_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
return mt.MailtrapClient(
token=API_TOKEN, sandbox=True, inbox_id="<YOUR_INBOX_ID>"
)
raise ValueError(f"Invalid sending type: {type_}")


batch_mail = mt.BatchSendEmailParams(
Expand Down
1 change: 1 addition & 0 deletions examples/sending/minimal_sending.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
return mt.MailtrapClient(
token=API_TOKEN, sandbox=True, inbox_id="<YOUR_INBOX_ID>"
)
raise ValueError(f"Invalid sending type: {type_}")


mail = mt.Mail(
Expand Down
1 change: 1 addition & 0 deletions examples/sending/sending_with_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
return mt.MailtrapClient(
token=API_TOKEN, sandbox=True, inbox_id="<YOUR_INBOX_ID>"
)
raise ValueError(f"Invalid sending type: {type_}")


mail = mt.MailFromTemplate(
Expand Down
6 changes: 5 additions & 1 deletion examples/suppressions/suppressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def delete_suppression(suppression_id: str) -> Suppression:


if __name__ == "__main__":
print(list_suppressions())
suppressions = list_suppressions()
print(suppressions)
if suppressions:
deleted_suppression = delete_suppression(suppressions[0].id)
print(deleted_suppression)
5 changes: 5 additions & 0 deletions examples/testing/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ def get_attachment(inbox_id: int, message_id: int, attachment_id: int) -> Attach
if __name__ == "__main__":
attachments = list_attachments(inbox_id=INBOX_ID, message_id=MESSAGE_ID)
print(attachments)
if attachments:
attachment = get_attachment(
inbox_id=INBOX_ID, message_id=MESSAGE_ID, attachment_id=attachments[0].id
)
print(attachment)
28 changes: 28 additions & 0 deletions examples/testing/inboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,31 @@ def delete_inbox(inbox_id: int):
if __name__ == "__main__":
inboxes = list_inboxes()
print(inboxes)

created = create_inbox(project_id=1, inbox_name="example-created-inbox")
print(created)

inbox_id = created.id
inbox = get_inbox_by_id(inbox_id=inbox_id)
print(inbox)

updated = update_inbox(inbox_id=inbox_id, new_name=f"{inbox.name}-updated")
print(updated)

cleaned = clean_inbox(inbox_id=inbox_id)
print(cleaned)

marked = mark_inbox_as_read(inbox_id=inbox_id)
print(marked)

reset_creds = reset_inbox_credentials(inbox_id=inbox_id)
print(reset_creds)

enabled = enable_inbox_email_address(inbox_id=inbox_id)
print(enabled)

reset_username = reset_inbox_email_username(inbox_id=inbox_id)
print(reset_username)

deleted = delete_inbox(inbox_id=inbox_id)
print(deleted)
38 changes: 38 additions & 0 deletions examples/testing/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,41 @@ def get_mail_headers(inbox_id: int, message_id: str) -> str:
if __name__ == "__main__":
messages = list_messages(inbox_id=INBOX_ID)
print(messages)
if messages:
msg_id = messages[0].id
message = get_message(inbox_id=INBOX_ID, message_id=msg_id)
print(message)

updated = update_message(inbox_id=INBOX_ID, message_id=msg_id, is_read=True)
print(updated)

forwarded = forward_message(
inbox_id=INBOX_ID,
message_id=msg_id,
email="[email protected]",
)
print(forwarded)

spam = get_spam_report(inbox_id=INBOX_ID, message_id=msg_id)
print(spam)

html_analysis = get_html_analysis(inbox_id=INBOX_ID, message_id=msg_id)
print(html_analysis)

text = get_text_message(inbox_id=INBOX_ID, message_id=msg_id)
print(text)

raw = get_raw_message(inbox_id=INBOX_ID, message_id=msg_id)
print(raw)

html_src = get_html_source(inbox_id=INBOX_ID, message_id=msg_id)
print(html_src)

html_msg = get_html_message(inbox_id=INBOX_ID, message_id=msg_id)
print(html_msg)

eml = get_message_as_eml(inbox_id=INBOX_ID, message_id=msg_id)
print(eml)

headers = get_mail_headers(inbox_id=INBOX_ID, message_id=msg_id)
print(headers)
12 changes: 12 additions & 0 deletions examples/testing/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ def delete_project(project_id: int):
if __name__ == "__main__":
projects = list_projects()
print(projects)

created = create_project(name="example-created-project")
print(created)

project = get_project(project_id=created.id)
print(project)

updated = update_project(project_id=created.id, new_name=f"{project.name}-updated")
print(updated)

deleted = delete_project(project_id=created.id)
print(deleted)