mailtrap 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mailtrap-2.2.0 → mailtrap-2.3.0}/PKG-INFO +1 -1
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/__init__.py +10 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/contacts.py +10 -0
- mailtrap-2.3.0/mailtrap/api/general.py +26 -0
- mailtrap-2.3.0/mailtrap/api/resources/account_accesses.py +43 -0
- mailtrap-2.3.0/mailtrap/api/resources/accounts.py +12 -0
- mailtrap-2.3.0/mailtrap/api/resources/billing.py +12 -0
- mailtrap-2.3.0/mailtrap/api/resources/contact_events.py +26 -0
- mailtrap-2.3.0/mailtrap/api/resources/contact_exports.py +32 -0
- mailtrap-2.3.0/mailtrap/api/resources/permissions.py +39 -0
- mailtrap-2.3.0/mailtrap/api/sending.py +36 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/client.py +20 -1
- mailtrap-2.3.0/mailtrap/models/accounts.py +44 -0
- mailtrap-2.3.0/mailtrap/models/billing.py +50 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/contacts.py +37 -0
- mailtrap-2.3.0/mailtrap/models/mail/__init__.py +29 -0
- mailtrap-2.3.0/mailtrap/models/mail/batch_mail.py +69 -0
- mailtrap-2.2.0/mailtrap/models/mail/base.py → mailtrap-2.3.0/mailtrap/models/mail/mail.py +16 -1
- mailtrap-2.3.0/mailtrap/models/permissions.py +35 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap.egg-info/PKG-INFO +1 -1
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap.egg-info/SOURCES.txt +10 -2
- {mailtrap-2.2.0 → mailtrap-2.3.0}/pyproject.toml +1 -1
- mailtrap-2.2.0/mailtrap/api/sending.py +0 -23
- mailtrap-2.2.0/mailtrap/models/mail/__init__.py +0 -15
- mailtrap-2.2.0/mailtrap/models/mail/from_template.py +0 -13
- mailtrap-2.2.0/mailtrap/models/mail/mail.py +0 -14
- mailtrap-2.2.0/mailtrap/models/permissions.py +0 -9
- {mailtrap-2.2.0 → mailtrap-2.3.0}/LICENSE.txt +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/README.md +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/__init__.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/__init__.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/attachments.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/contact_fields.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/contact_imports.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/contact_lists.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/contacts.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/inboxes.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/messages.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/projects.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/suppressions.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/resources/templates.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/suppressions.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/templates.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/api/testing.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/config.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/exceptions.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/http.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/__init__.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/attachments.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/common.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/inboxes.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/mail/address.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/mail/attachment.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/messages.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/projects.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/suppressions.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap/models/templates.py +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap.egg-info/dependency_links.txt +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap.egg-info/requires.txt +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/mailtrap.egg-info/top_level.txt +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/requirements.txt +0 -0
- {mailtrap-2.2.0 → mailtrap-2.3.0}/setup.cfg +0 -0
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
from .client import BATCH_SEND_ENDPOINT_RESPONSE
|
|
1
2
|
from .client import SEND_ENDPOINT_RESPONSE
|
|
2
3
|
from .client import MailtrapClient
|
|
3
4
|
from .exceptions import APIError
|
|
4
5
|
from .exceptions import AuthorizationError
|
|
5
6
|
from .exceptions import ClientConfigurationError
|
|
6
7
|
from .exceptions import MailtrapError
|
|
8
|
+
from .models.accounts import AccountAccessFilterParams
|
|
9
|
+
from .models.contacts import ContactEventParams
|
|
10
|
+
from .models.contacts import ContactExportFilter
|
|
7
11
|
from .models.contacts import ContactListParams
|
|
12
|
+
from .models.contacts import CreateContactExportParams
|
|
8
13
|
from .models.contacts import CreateContactFieldParams
|
|
9
14
|
from .models.contacts import CreateContactParams
|
|
10
15
|
from .models.contacts import ImportContactParams
|
|
@@ -15,10 +20,15 @@ from .models.inboxes import UpdateInboxParams
|
|
|
15
20
|
from .models.mail import Address
|
|
16
21
|
from .models.mail import Attachment
|
|
17
22
|
from .models.mail import BaseMail
|
|
23
|
+
from .models.mail import BatchEmailRequest
|
|
24
|
+
from .models.mail import BatchMail
|
|
25
|
+
from .models.mail import BatchMailFromTemplate
|
|
26
|
+
from .models.mail import BatchSendEmailParams
|
|
18
27
|
from .models.mail import Disposition
|
|
19
28
|
from .models.mail import Mail
|
|
20
29
|
from .models.mail import MailFromTemplate
|
|
21
30
|
from .models.messages import UpdateEmailMessageParams
|
|
31
|
+
from .models.permissions import PermissionResourceParams
|
|
22
32
|
from .models.projects import ProjectParams
|
|
23
33
|
from .models.templates import CreateEmailTemplateParams
|
|
24
34
|
from .models.templates import UpdateEmailTemplateParams
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from mailtrap.api.resources.contact_events import ContactEventsApi
|
|
2
|
+
from mailtrap.api.resources.contact_exports import ContactExportsApi
|
|
1
3
|
from mailtrap.api.resources.contact_fields import ContactFieldsApi
|
|
2
4
|
from mailtrap.api.resources.contact_imports import ContactImportsApi
|
|
3
5
|
from mailtrap.api.resources.contact_lists import ContactListsApi
|
|
@@ -10,6 +12,14 @@ class ContactsBaseApi:
|
|
|
10
12
|
self._account_id = account_id
|
|
11
13
|
self._client = client
|
|
12
14
|
|
|
15
|
+
@property
|
|
16
|
+
def contact_events(self) -> ContactEventsApi:
|
|
17
|
+
return ContactEventsApi(account_id=self._account_id, client=self._client)
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def contact_exports(self) -> ContactExportsApi:
|
|
21
|
+
return ContactExportsApi(account_id=self._account_id, client=self._client)
|
|
22
|
+
|
|
13
23
|
@property
|
|
14
24
|
def contact_fields(self) -> ContactFieldsApi:
|
|
15
25
|
return ContactFieldsApi(account_id=self._account_id, client=self._client)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from mailtrap.api.resources.account_accesses import AccountAccessesApi
|
|
2
|
+
from mailtrap.api.resources.accounts import AccountsApi
|
|
3
|
+
from mailtrap.api.resources.billing import BillingApi
|
|
4
|
+
from mailtrap.api.resources.permissions import PermissionsApi
|
|
5
|
+
from mailtrap.http import HttpClient
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GeneralApi:
|
|
9
|
+
def __init__(self, client: HttpClient) -> None:
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
@property
|
|
13
|
+
def accounts(self) -> AccountsApi:
|
|
14
|
+
return AccountsApi(client=self._client)
|
|
15
|
+
|
|
16
|
+
@property
|
|
17
|
+
def account_accesses(self) -> AccountAccessesApi:
|
|
18
|
+
return AccountAccessesApi(client=self._client)
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def billing(self) -> BillingApi:
|
|
22
|
+
return BillingApi(client=self._client)
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def permissions(self) -> PermissionsApi:
|
|
26
|
+
return PermissionsApi(client=self._client)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from urllib.parse import quote
|
|
3
|
+
|
|
4
|
+
from mailtrap.http import HttpClient
|
|
5
|
+
from mailtrap.models.accounts import AccountAccess
|
|
6
|
+
from mailtrap.models.accounts import AccountAccessFilterParams
|
|
7
|
+
from mailtrap.models.common import DeletedObject
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AccountAccessesApi:
|
|
11
|
+
def __init__(self, client: HttpClient) -> None:
|
|
12
|
+
self._client = client
|
|
13
|
+
|
|
14
|
+
def get_list(
|
|
15
|
+
self, account_id: int, filter_params: Optional[AccountAccessFilterParams] = None
|
|
16
|
+
) -> list[AccountAccess]:
|
|
17
|
+
"""
|
|
18
|
+
Get list of account accesses for which specifier_type is User or Invite.
|
|
19
|
+
You have to have account admin/owner permissions for this endpoint to work.
|
|
20
|
+
If you specify project_ids, inbox_ids or domain_ids, the endpoint will return
|
|
21
|
+
account accesses for these resources.
|
|
22
|
+
"""
|
|
23
|
+
response = self._client.get(
|
|
24
|
+
self._api_path(account_id),
|
|
25
|
+
params=filter_params.api_data if filter_params else None,
|
|
26
|
+
)
|
|
27
|
+
return [AccountAccess(**account_access) for account_access in response]
|
|
28
|
+
|
|
29
|
+
def delete(self, account_id: int, account_access_id: int) -> DeletedObject:
|
|
30
|
+
"""
|
|
31
|
+
If specifier type is User, it removes user permissions.
|
|
32
|
+
If specifier type is Invite or ApiToken, it removes specifier
|
|
33
|
+
along with permissions. You have to be an account admin/owner
|
|
34
|
+
for this method to work.
|
|
35
|
+
"""
|
|
36
|
+
self._client.delete(self._api_path(account_id, account_access_id))
|
|
37
|
+
return DeletedObject(account_access_id)
|
|
38
|
+
|
|
39
|
+
def _api_path(self, account_id: int, account_access_id: Optional[int] = None) -> str:
|
|
40
|
+
path = f"/api/accounts/{account_id}/account_accesses"
|
|
41
|
+
if account_access_id is not None:
|
|
42
|
+
return f"{path}/{quote(str(account_access_id), safe='')}"
|
|
43
|
+
return path
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from mailtrap.http import HttpClient
|
|
2
|
+
from mailtrap.models.accounts import Account
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AccountsApi:
|
|
6
|
+
def __init__(self, client: HttpClient) -> None:
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def get_list(self) -> list[Account]:
|
|
10
|
+
"""Get a list of your Mailtrap accounts."""
|
|
11
|
+
response = self._client.get("/api/accounts")
|
|
12
|
+
return [Account(**account) for account in response]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from mailtrap.http import HttpClient
|
|
2
|
+
from mailtrap.models.billing import BillingCycleUsage
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BillingApi:
|
|
6
|
+
def __init__(self, client: HttpClient) -> None:
|
|
7
|
+
self._client = client
|
|
8
|
+
|
|
9
|
+
def get_current_billing_usage(self, account_id: int) -> BillingCycleUsage:
|
|
10
|
+
"""Get current billing cycle usage for Email Testing and Email Sending."""
|
|
11
|
+
response = self._client.get(f"/api/accounts/{account_id}/billing/usage")
|
|
12
|
+
return BillingCycleUsage(**response)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from mailtrap.http import HttpClient
|
|
4
|
+
from mailtrap.models.contacts import ContactEvent
|
|
5
|
+
from mailtrap.models.contacts import ContactEventParams
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ContactEventsApi:
|
|
9
|
+
def __init__(self, client: HttpClient, account_id: str) -> None:
|
|
10
|
+
self._account_id = account_id
|
|
11
|
+
self._client = client
|
|
12
|
+
|
|
13
|
+
def create(
|
|
14
|
+
self,
|
|
15
|
+
contact_identifier: str,
|
|
16
|
+
contact_event_params: ContactEventParams,
|
|
17
|
+
) -> ContactEvent:
|
|
18
|
+
"""Create a new Contact Event"""
|
|
19
|
+
response = self._client.post(
|
|
20
|
+
self._api_path(contact_identifier),
|
|
21
|
+
json=contact_event_params.api_data,
|
|
22
|
+
)
|
|
23
|
+
return ContactEvent(**response)
|
|
24
|
+
|
|
25
|
+
def _api_path(self, contact_identifier: Optional[str] = None) -> str:
|
|
26
|
+
return f"/api/accounts/{self._account_id}/contacts/{contact_identifier}/events"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from mailtrap.http import HttpClient
|
|
4
|
+
from mailtrap.models.contacts import ContactExportDetail
|
|
5
|
+
from mailtrap.models.contacts import CreateContactExportParams
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ContactExportsApi:
|
|
9
|
+
def __init__(self, client: HttpClient, account_id: str) -> None:
|
|
10
|
+
self._account_id = account_id
|
|
11
|
+
self._client = client
|
|
12
|
+
|
|
13
|
+
def create(
|
|
14
|
+
self, contact_exports_params: CreateContactExportParams
|
|
15
|
+
) -> ContactExportDetail:
|
|
16
|
+
"""Create a new Contact Export"""
|
|
17
|
+
response = self._client.post(
|
|
18
|
+
self._api_path(),
|
|
19
|
+
json=contact_exports_params.api_data,
|
|
20
|
+
)
|
|
21
|
+
return ContactExportDetail(**response)
|
|
22
|
+
|
|
23
|
+
def get_by_id(self, export_id: int) -> ContactExportDetail:
|
|
24
|
+
"""Get Contact Export"""
|
|
25
|
+
response = self._client.get(self._api_path(export_id))
|
|
26
|
+
return ContactExportDetail(**response)
|
|
27
|
+
|
|
28
|
+
def _api_path(self, export_id: Optional[int] = None) -> str:
|
|
29
|
+
path = f"/api/accounts/{self._account_id}/contacts/exports"
|
|
30
|
+
if export_id is not None:
|
|
31
|
+
return f"{path}/{export_id}"
|
|
32
|
+
return path
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from mailtrap.http import HttpClient
|
|
2
|
+
from mailtrap.models.permissions import PermissionResource
|
|
3
|
+
from mailtrap.models.permissions import PermissionResourceParams
|
|
4
|
+
from mailtrap.models.permissions import UpdatePermissionsResponse
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PermissionsApi:
|
|
8
|
+
def __init__(self, client: HttpClient) -> None:
|
|
9
|
+
self._client = client
|
|
10
|
+
|
|
11
|
+
def get_resources(self, account_id: int) -> list[PermissionResource]:
|
|
12
|
+
"""
|
|
13
|
+
Get all resources in your account (Inboxes, Projects, Domains,
|
|
14
|
+
Email Campaigns, Billing and Account itself) to which the token
|
|
15
|
+
has admin access.
|
|
16
|
+
"""
|
|
17
|
+
response = self._client.get(f"/api/accounts/{account_id}/permissions/resources")
|
|
18
|
+
return [PermissionResource(**resource) for resource in response]
|
|
19
|
+
|
|
20
|
+
def bulk_permissions_update(
|
|
21
|
+
self,
|
|
22
|
+
account_id: int,
|
|
23
|
+
account_access_id: int,
|
|
24
|
+
permissions: list[PermissionResourceParams],
|
|
25
|
+
) -> UpdatePermissionsResponse:
|
|
26
|
+
"""
|
|
27
|
+
Manage user or token permissions. For this endpoint, you should send
|
|
28
|
+
an array of objects (in JSON format) as the body of the request.
|
|
29
|
+
If you send a combination of resource_type and resource_id that already exists,
|
|
30
|
+
the permission is updated. If the combination doesn't exist,
|
|
31
|
+
the permission is created.
|
|
32
|
+
"""
|
|
33
|
+
response = self._client.put(
|
|
34
|
+
f"/api/accounts/{account_id}"
|
|
35
|
+
f"/account_accesses/{account_access_id}"
|
|
36
|
+
"/permissions/bulk",
|
|
37
|
+
json={"permissions": [resource.api_data for resource in permissions]},
|
|
38
|
+
)
|
|
39
|
+
return UpdatePermissionsResponse(**response)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from mailtrap.http import HttpClient
|
|
4
|
+
from mailtrap.models.mail import BaseMail
|
|
5
|
+
from mailtrap.models.mail import SendingMailResponse
|
|
6
|
+
from mailtrap.models.mail.batch_mail import BatchSendEmailParams
|
|
7
|
+
from mailtrap.models.mail.batch_mail import BatchSendResponse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SendingApi:
|
|
11
|
+
def __init__(self, client: HttpClient, inbox_id: Optional[str] = None) -> None:
|
|
12
|
+
self._inbox_id = inbox_id
|
|
13
|
+
self._client = client
|
|
14
|
+
|
|
15
|
+
def _get_api_url(self, base_url: str) -> str:
|
|
16
|
+
if self._inbox_id:
|
|
17
|
+
return f"{base_url}/{self._inbox_id}"
|
|
18
|
+
return base_url
|
|
19
|
+
|
|
20
|
+
def send(self, mail: BaseMail) -> SendingMailResponse:
|
|
21
|
+
"""Send email (text, html, text&html, templates)."""
|
|
22
|
+
response = self._client.post(self._get_api_url("/api/send"), json=mail.api_data)
|
|
23
|
+
return SendingMailResponse(**response)
|
|
24
|
+
|
|
25
|
+
def batch_send(self, mail: BatchSendEmailParams) -> BatchSendResponse:
|
|
26
|
+
"""
|
|
27
|
+
Batch send email (text, html, text&html, templates). Please note that
|
|
28
|
+
the endpoint will return a 200-level http status, even when sending
|
|
29
|
+
for individual messages may fail. Users of this endpoint should check
|
|
30
|
+
the success and errors for each message in the response (the results
|
|
31
|
+
are ordered the same as the original messages - requests). Please note
|
|
32
|
+
that the endpoint accepts up to 500 messages per API call, and up to 50 MB
|
|
33
|
+
payload size, including attachments.
|
|
34
|
+
"""
|
|
35
|
+
response = self._client.post(self._get_api_url("/api/batch"), json=mail.api_data)
|
|
36
|
+
return BatchSendResponse(**response)
|
|
@@ -6,6 +6,7 @@ from typing import cast
|
|
|
6
6
|
from pydantic import TypeAdapter
|
|
7
7
|
|
|
8
8
|
from mailtrap.api.contacts import ContactsBaseApi
|
|
9
|
+
from mailtrap.api.general import GeneralApi
|
|
9
10
|
from mailtrap.api.sending import SendingApi
|
|
10
11
|
from mailtrap.api.suppressions import SuppressionsBaseApi
|
|
11
12
|
from mailtrap.api.templates import EmailTemplatesApi
|
|
@@ -17,9 +18,14 @@ from mailtrap.config import SENDING_HOST
|
|
|
17
18
|
from mailtrap.exceptions import ClientConfigurationError
|
|
18
19
|
from mailtrap.http import HttpClient
|
|
19
20
|
from mailtrap.models.mail import BaseMail
|
|
20
|
-
from mailtrap.models.mail
|
|
21
|
+
from mailtrap.models.mail import BatchSendResponse
|
|
22
|
+
from mailtrap.models.mail import SendingMailResponse
|
|
23
|
+
from mailtrap.models.mail.batch_mail import BatchSendEmailParams
|
|
21
24
|
|
|
22
25
|
SEND_ENDPOINT_RESPONSE = dict[str, Union[bool, list[str]]]
|
|
26
|
+
BATCH_SEND_ENDPOINT_RESPONSE = dict[
|
|
27
|
+
str, Union[bool, list[str], list[dict[str, Union[bool, list[str]]]]]
|
|
28
|
+
]
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
class MailtrapClient:
|
|
@@ -48,6 +54,12 @@ class MailtrapClient:
|
|
|
48
54
|
|
|
49
55
|
self._validate_itself()
|
|
50
56
|
|
|
57
|
+
@property
|
|
58
|
+
def general_api(self) -> GeneralApi:
|
|
59
|
+
return GeneralApi(
|
|
60
|
+
client=HttpClient(host=GENERAL_HOST, headers=self.headers),
|
|
61
|
+
)
|
|
62
|
+
|
|
51
63
|
@property
|
|
52
64
|
def testing_api(self) -> TestingApi:
|
|
53
65
|
self._validate_account_id()
|
|
@@ -93,6 +105,13 @@ class MailtrapClient:
|
|
|
93
105
|
TypeAdapter(SendingMailResponse).dump_python(sending_response),
|
|
94
106
|
)
|
|
95
107
|
|
|
108
|
+
def batch_send(self, mail: BatchSendEmailParams) -> BATCH_SEND_ENDPOINT_RESPONSE:
|
|
109
|
+
batch_sending_response = self.sending_api.batch_send(mail)
|
|
110
|
+
return cast(
|
|
111
|
+
BATCH_SEND_ENDPOINT_RESPONSE,
|
|
112
|
+
TypeAdapter(BatchSendResponse).dump_python(batch_sending_response),
|
|
113
|
+
)
|
|
114
|
+
|
|
96
115
|
@property
|
|
97
116
|
def base_url(self) -> str:
|
|
98
117
|
warnings.warn(
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic.dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from mailtrap.models.common import RequestParams
|
|
6
|
+
from mailtrap.models.permissions import Permissions
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class AccountAccessFilterParams(RequestParams):
|
|
11
|
+
domain_ids: Optional[list[str]] = None
|
|
12
|
+
inbox_ids: Optional[list[str]] = None
|
|
13
|
+
project_ids: Optional[list[str]] = None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class Account:
|
|
18
|
+
id: int
|
|
19
|
+
name: str
|
|
20
|
+
access_levels: list[int]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Specifier:
|
|
25
|
+
id: int
|
|
26
|
+
email: str
|
|
27
|
+
name: str
|
|
28
|
+
two_factor_authentication_enabled: bool
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class AccountAccessResource:
|
|
33
|
+
resource_id: int
|
|
34
|
+
resource_type: str
|
|
35
|
+
access_level: int
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class AccountAccess:
|
|
40
|
+
id: int
|
|
41
|
+
specifier_type: str
|
|
42
|
+
specifier: Specifier
|
|
43
|
+
resources: list[AccountAccessResource]
|
|
44
|
+
permissions: Permissions
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
from pydantic.dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class MessagesCount:
|
|
8
|
+
current: int
|
|
9
|
+
limit: int
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class UsageTesting:
|
|
14
|
+
sent_messages_count: MessagesCount
|
|
15
|
+
forwarded_messages_count: MessagesCount
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class UsageSending:
|
|
20
|
+
sent_messages_count: MessagesCount
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Plan:
|
|
25
|
+
name: str
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Testing:
|
|
30
|
+
plan: Plan
|
|
31
|
+
usage: UsageTesting
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class Sending:
|
|
36
|
+
plan: Plan
|
|
37
|
+
usage: UsageSending
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class Billing:
|
|
42
|
+
cycle_start: datetime
|
|
43
|
+
cycle_end: datetime
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class BillingCycleUsage:
|
|
48
|
+
billing: Billing
|
|
49
|
+
testing: Testing
|
|
50
|
+
sending: Sending
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
from datetime import datetime
|
|
1
2
|
from enum import Enum
|
|
3
|
+
from typing import Any
|
|
2
4
|
from typing import Optional
|
|
3
5
|
from typing import Union
|
|
4
6
|
|
|
@@ -121,3 +123,38 @@ class ImportContactParams(RequestParams):
|
|
|
121
123
|
)
|
|
122
124
|
list_ids_included: Optional[list[int]] = None
|
|
123
125
|
list_ids_excluded: Optional[list[int]] = None
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@dataclass
|
|
129
|
+
class ContactExportFilter(RequestParams):
|
|
130
|
+
name: str
|
|
131
|
+
operator: str
|
|
132
|
+
value: list[int]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@dataclass
|
|
136
|
+
class CreateContactExportParams(RequestParams):
|
|
137
|
+
filters: list[ContactExportFilter]
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@dataclass
|
|
141
|
+
class ContactExportDetail:
|
|
142
|
+
id: int
|
|
143
|
+
status: str
|
|
144
|
+
created_at: datetime
|
|
145
|
+
updated_at: datetime
|
|
146
|
+
url: Optional[str] = None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@dataclass
|
|
150
|
+
class ContactEventParams(RequestParams):
|
|
151
|
+
name: str
|
|
152
|
+
params: Optional[dict[str, Any]] = None
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@dataclass
|
|
156
|
+
class ContactEvent:
|
|
157
|
+
contact_id: str
|
|
158
|
+
contact_email: str
|
|
159
|
+
name: str
|
|
160
|
+
params: Optional[dict[str, Any]] = None
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from mailtrap.models.mail.address import Address
|
|
2
|
+
from mailtrap.models.mail.attachment import Attachment
|
|
3
|
+
from mailtrap.models.mail.attachment import Disposition
|
|
4
|
+
from mailtrap.models.mail.batch_mail import BaseBatchMail
|
|
5
|
+
from mailtrap.models.mail.batch_mail import BatchEmailRequest
|
|
6
|
+
from mailtrap.models.mail.batch_mail import BatchMail
|
|
7
|
+
from mailtrap.models.mail.batch_mail import BatchMailFromTemplate
|
|
8
|
+
from mailtrap.models.mail.batch_mail import BatchSendEmailParams
|
|
9
|
+
from mailtrap.models.mail.batch_mail import BatchSendResponse
|
|
10
|
+
from mailtrap.models.mail.mail import BaseMail
|
|
11
|
+
from mailtrap.models.mail.mail import Mail
|
|
12
|
+
from mailtrap.models.mail.mail import MailFromTemplate
|
|
13
|
+
from mailtrap.models.mail.mail import SendingMailResponse
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"Address",
|
|
17
|
+
"Attachment",
|
|
18
|
+
"BaseBatchMail",
|
|
19
|
+
"BaseMail",
|
|
20
|
+
"BatchEmailRequest",
|
|
21
|
+
"BatchMail",
|
|
22
|
+
"BatchMailFromTemplate",
|
|
23
|
+
"BatchSendEmailParams",
|
|
24
|
+
"BatchSendResponse",
|
|
25
|
+
"Disposition",
|
|
26
|
+
"Mail",
|
|
27
|
+
"MailFromTemplate",
|
|
28
|
+
"SendingMailResponse",
|
|
29
|
+
]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from typing import Optional
|
|
3
|
+
from typing import Union
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from pydantic.dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from mailtrap.models.common import RequestParams
|
|
9
|
+
from mailtrap.models.mail.address import Address
|
|
10
|
+
from mailtrap.models.mail.attachment import Attachment
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class BaseBatchMail(RequestParams):
|
|
15
|
+
sender: Address = Field(..., serialization_alias="from")
|
|
16
|
+
attachments: Optional[list[Attachment]] = None
|
|
17
|
+
headers: Optional[dict[str, str]] = None
|
|
18
|
+
custom_variables: Optional[dict[str, Any]] = None
|
|
19
|
+
reply_to: Optional[Address] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class BatchMail(BaseBatchMail):
|
|
24
|
+
subject: str = Field(...) # type:ignore
|
|
25
|
+
text: Optional[str] = None
|
|
26
|
+
html: Optional[str] = None
|
|
27
|
+
category: Optional[str] = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class BatchMailFromTemplate(BaseBatchMail):
|
|
32
|
+
template_uuid: str = Field(...) # type:ignore
|
|
33
|
+
template_variables: Optional[dict[str, Any]] = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class BatchEmailRequest(BaseBatchMail):
|
|
38
|
+
to: list[Address] = Field(...) # type:ignore
|
|
39
|
+
sender: Optional[Address] = Field(
|
|
40
|
+
None, serialization_alias="from"
|
|
41
|
+
) # type: ignore[assignment]
|
|
42
|
+
cc: Optional[list[Address]] = None
|
|
43
|
+
bcc: Optional[list[Address]] = None
|
|
44
|
+
subject: Optional[str] = None
|
|
45
|
+
text: Optional[str] = None
|
|
46
|
+
html: Optional[str] = None
|
|
47
|
+
category: Optional[str] = None
|
|
48
|
+
template_uuid: Optional[str] = None
|
|
49
|
+
template_variables: Optional[dict[str, Any]] = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class BatchSendEmailParams(RequestParams):
|
|
54
|
+
base: Union[BatchMail, BatchMailFromTemplate]
|
|
55
|
+
requests: list[BatchEmailRequest]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class BatchSendResponseItem:
|
|
60
|
+
success: bool
|
|
61
|
+
message_ids: Optional[list[str]] = None
|
|
62
|
+
errors: Optional[list[str]] = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class BatchSendResponse:
|
|
67
|
+
success: bool
|
|
68
|
+
responses: list[BatchSendResponseItem]
|
|
69
|
+
errors: Optional[list[str]] = None
|
|
@@ -11,13 +11,28 @@ from mailtrap.models.mail.attachment import Attachment
|
|
|
11
11
|
|
|
12
12
|
@dataclass
|
|
13
13
|
class BaseMail(RequestParams):
|
|
14
|
+
to: list[Address]
|
|
14
15
|
sender: Address = Field(..., serialization_alias="from")
|
|
15
|
-
to: list[Address] = Field(...)
|
|
16
16
|
cc: Optional[list[Address]] = None
|
|
17
17
|
bcc: Optional[list[Address]] = None
|
|
18
18
|
attachments: Optional[list[Attachment]] = None
|
|
19
19
|
headers: Optional[dict[str, str]] = None
|
|
20
20
|
custom_variables: Optional[dict[str, Any]] = None
|
|
21
|
+
reply_to: Optional[Address] = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Mail(BaseMail):
|
|
26
|
+
subject: str = Field(...) # type:ignore
|
|
27
|
+
text: Optional[str] = None
|
|
28
|
+
html: Optional[str] = None
|
|
29
|
+
category: Optional[str] = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class MailFromTemplate(BaseMail):
|
|
34
|
+
template_uuid: str = Field(...) # type:ignore
|
|
35
|
+
template_variables: Optional[dict[str, Any]] = None
|
|
21
36
|
|
|
22
37
|
|
|
23
38
|
@dataclass
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pydantic.dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from mailtrap.models.common import RequestParams
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class Permissions:
|
|
10
|
+
can_read: bool
|
|
11
|
+
can_update: bool
|
|
12
|
+
can_destroy: bool
|
|
13
|
+
can_leave: bool
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class PermissionResource:
|
|
18
|
+
id: int
|
|
19
|
+
name: str
|
|
20
|
+
type: str
|
|
21
|
+
access_level: int
|
|
22
|
+
resources: list["PermissionResource"]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class PermissionResourceParams(RequestParams):
|
|
27
|
+
resource_id: str
|
|
28
|
+
resource_type: str
|
|
29
|
+
access_level: Optional[str] = None
|
|
30
|
+
_destroy: Optional[bool] = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class UpdatePermissionsResponse:
|
|
35
|
+
message: str
|
|
@@ -14,23 +14,32 @@ mailtrap.egg-info/requires.txt
|
|
|
14
14
|
mailtrap.egg-info/top_level.txt
|
|
15
15
|
mailtrap/api/__init__.py
|
|
16
16
|
mailtrap/api/contacts.py
|
|
17
|
+
mailtrap/api/general.py
|
|
17
18
|
mailtrap/api/sending.py
|
|
18
19
|
mailtrap/api/suppressions.py
|
|
19
20
|
mailtrap/api/templates.py
|
|
20
21
|
mailtrap/api/testing.py
|
|
21
22
|
mailtrap/api/resources/__init__.py
|
|
23
|
+
mailtrap/api/resources/account_accesses.py
|
|
24
|
+
mailtrap/api/resources/accounts.py
|
|
22
25
|
mailtrap/api/resources/attachments.py
|
|
26
|
+
mailtrap/api/resources/billing.py
|
|
27
|
+
mailtrap/api/resources/contact_events.py
|
|
28
|
+
mailtrap/api/resources/contact_exports.py
|
|
23
29
|
mailtrap/api/resources/contact_fields.py
|
|
24
30
|
mailtrap/api/resources/contact_imports.py
|
|
25
31
|
mailtrap/api/resources/contact_lists.py
|
|
26
32
|
mailtrap/api/resources/contacts.py
|
|
27
33
|
mailtrap/api/resources/inboxes.py
|
|
28
34
|
mailtrap/api/resources/messages.py
|
|
35
|
+
mailtrap/api/resources/permissions.py
|
|
29
36
|
mailtrap/api/resources/projects.py
|
|
30
37
|
mailtrap/api/resources/suppressions.py
|
|
31
38
|
mailtrap/api/resources/templates.py
|
|
32
39
|
mailtrap/models/__init__.py
|
|
40
|
+
mailtrap/models/accounts.py
|
|
33
41
|
mailtrap/models/attachments.py
|
|
42
|
+
mailtrap/models/billing.py
|
|
34
43
|
mailtrap/models/common.py
|
|
35
44
|
mailtrap/models/contacts.py
|
|
36
45
|
mailtrap/models/inboxes.py
|
|
@@ -42,6 +51,5 @@ mailtrap/models/templates.py
|
|
|
42
51
|
mailtrap/models/mail/__init__.py
|
|
43
52
|
mailtrap/models/mail/address.py
|
|
44
53
|
mailtrap/models/mail/attachment.py
|
|
45
|
-
mailtrap/models/mail/
|
|
46
|
-
mailtrap/models/mail/from_template.py
|
|
54
|
+
mailtrap/models/mail/batch_mail.py
|
|
47
55
|
mailtrap/models/mail/mail.py
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from mailtrap.http import HttpClient
|
|
4
|
-
from mailtrap.models.mail.base import BaseMail
|
|
5
|
-
from mailtrap.models.mail.base import SendingMailResponse
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SendingApi:
|
|
9
|
-
def __init__(self, client: HttpClient, inbox_id: Optional[str] = None) -> None:
|
|
10
|
-
self._inbox_id = inbox_id
|
|
11
|
-
self._client = client
|
|
12
|
-
|
|
13
|
-
@property
|
|
14
|
-
def _api_url(self) -> str:
|
|
15
|
-
url = "/api/send"
|
|
16
|
-
if self._inbox_id:
|
|
17
|
-
return f"{url}/{self._inbox_id}"
|
|
18
|
-
return url
|
|
19
|
-
|
|
20
|
-
def send(self, mail: BaseMail) -> SendingMailResponse:
|
|
21
|
-
"""Send email (text, html, text&html, templates)."""
|
|
22
|
-
response = self._client.post(self._api_url, json=mail.api_data)
|
|
23
|
-
return SendingMailResponse(**response)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from mailtrap.models.mail.address import Address
|
|
2
|
-
from mailtrap.models.mail.attachment import Attachment
|
|
3
|
-
from mailtrap.models.mail.attachment import Disposition
|
|
4
|
-
from mailtrap.models.mail.base import BaseMail
|
|
5
|
-
from mailtrap.models.mail.from_template import MailFromTemplate
|
|
6
|
-
from mailtrap.models.mail.mail import Mail
|
|
7
|
-
|
|
8
|
-
__all__ = [
|
|
9
|
-
"Address",
|
|
10
|
-
"Attachment",
|
|
11
|
-
"Disposition",
|
|
12
|
-
"BaseMail",
|
|
13
|
-
"Mail",
|
|
14
|
-
"MailFromTemplate",
|
|
15
|
-
]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
from pydantic import Field
|
|
5
|
-
from pydantic.dataclasses import dataclass
|
|
6
|
-
|
|
7
|
-
from mailtrap.models.mail.base import BaseMail
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@dataclass
|
|
11
|
-
class MailFromTemplate(BaseMail):
|
|
12
|
-
template_uuid: str = Field(...) # type:ignore
|
|
13
|
-
template_variables: Optional[dict[str, Any]] = None
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
from pydantic.dataclasses import dataclass
|
|
5
|
-
|
|
6
|
-
from mailtrap.models.mail.base import BaseMail
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@dataclass
|
|
10
|
-
class Mail(BaseMail):
|
|
11
|
-
subject: str = Field(...) # type:ignore
|
|
12
|
-
text: Optional[str] = None
|
|
13
|
-
html: Optional[str] = None
|
|
14
|
-
category: Optional[str] = None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|