-
Notifications
You must be signed in to change notification settings - Fork 8
Issue 25 #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Issue 25 #33
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9736d1
Fix issue #25: Add SendingApi and pydantic.dataclasses models for mail
b0f2dfa
Fix issue #25: Add SendingApi protocol, tests and examples
7b1e44f
Fix issue #25: Get rid of old models
27e299c
Fix issue #25: Add return type in examples function
c21e0fc
Fix issue #25: Add SendingMailResponse model, simplify SendingApi class
2f2a229
Fix issue #25: Revert removing constants from MailtrapClient class
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import mailtrap as mt | ||
|
||
API_TOKEN = "<YOU_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="<YOUT_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) | ||
|
||
|
||
def batch_send(client: mt.MailtrapClient, mail: mt.BaseMail) -> mt.SEND_ENDPOINT_RESPONSE: | ||
# will be added soon | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
print(send(default_client, mail)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from .client import SEND_ENDPOINT_RESPONSE | ||
from .client import MailtrapClient | ||
from .exceptions import APIError | ||
from .exceptions import AuthorizationError | ||
from .exceptions import ClientConfigurationError | ||
from .exceptions import MailtrapError | ||
from .mail import Address | ||
from .mail import Attachment | ||
from .mail import BaseEntity | ||
from .mail import BaseMail | ||
from .mail import Disposition | ||
from .mail import Mail | ||
from .mail import MailFromTemplate | ||
from .models.mail import Address | ||
from .models.mail import Attachment | ||
from .models.mail import BaseMail | ||
from .models.mail import Disposition | ||
from .models.mail import Mail | ||
from .models.mail import MailFromTemplate | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Optional | ||
|
||
from mailtrap.http import HttpClient | ||
from mailtrap.models.mail.base import BaseMail | ||
from mailtrap.models.mail.base import SendingMailResponse | ||
|
||
|
||
class SendingApi: | ||
def __init__(self, client: HttpClient, inbox_id: Optional[str] = None) -> None: | ||
self._inbox_id = inbox_id | ||
self._client = client | ||
|
||
@property | ||
def _api_url(self) -> str: | ||
url = "/api/send" | ||
if self._inbox_id: | ||
return f"{url}/{self._inbox_id}" | ||
return url | ||
|
||
def send(self, mail: BaseMail) -> SendingMailResponse: | ||
response = self._client.post(self._api_url, json=mail.api_data) | ||
return SendingMailResponse(**response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
GENERAL_HOST = "mailtrap.io" | ||
BULK_HOST = "bulk.api.mailtrap.io" | ||
SANDBOX_HOST = "sandbox.api.mailtrap.io" | ||
SENDING_HOST = "send.api.mailtrap.io" | ||
|
||
DEFAULT_REQUEST_TIMEOUT = 30 # in seconds |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.