Skip to content

Commit 5b71d39

Browse files
Initial commit
0 parents  commit 5b71d39

30 files changed

+1041
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Motivation
2+
3+
## Changes
4+
5+
- Change 1
6+
- Change 2
7+
8+
## How to test
9+
10+
- [ ] Test 1
11+
- [ ] Test 2
12+
13+
## Images and GIFs
14+
15+
| Before | After |
16+
|--------|--------|
17+
| link1 | link2 |
18+
| link3 | link4 |
19+
| link5 | link6 |
20+
| link7 | link8 |
21+
| link9 | link10 |

.github/workflows/main.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Tests and checks
2+
3+
on: push
4+
5+
jobs:
6+
check:
7+
name: Test python${{ matrix.python }} on ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os:
12+
- "ubuntu-20.04"
13+
- "windows-latest"
14+
- "macos-latest"
15+
python:
16+
- "3.6"
17+
- "3.7"
18+
- "3.8"
19+
- "3.9"
20+
- "3.10"
21+
- "3.11"
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Setup python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: ${{ matrix.python }}
28+
- name: Install tox
29+
run: pip install tox
30+
- name: Run tests
31+
run: tox -e py${{ matrix.python }}
32+
- name: Run linters
33+
run: tox -e pre-commit
34+
- name: Run type checking
35+
run: tox -e mypy

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
4+
# Distribution / packaging
5+
dist/
6+
*.egg-info/
7+
8+
# IntelliJ's project specific settings
9+
.idea/
10+
11+
# mypy
12+
.mypy_cache/
13+
14+
# tox
15+
.tox/
16+
17+
# tests
18+
.pytest_cache
19+
20+
# venv
21+
venv

.pre-commit-config.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
repos:
2+
- repo: https://github.com/PyCQA/flake8
3+
rev: 5.0.4
4+
hooks:
5+
- id: flake8
6+
name: Style Guide Enforcement (flake8)
7+
args:
8+
- '--max-line-length=90'
9+
- '--per-file-ignores=__init__.py:F401'
10+
- repo: https://github.com/asottile/pyupgrade
11+
rev: v2.31.0
12+
hooks:
13+
- id: pyupgrade
14+
name: Upgrade syntax for newer versions of the language (pyupgrade)
15+
args:
16+
- '--py36-plus'
17+
# - repo: https://github.com/pycqa/isort
18+
# rev: 5.10.0
19+
# hooks:
20+
# - id: isort
21+
# name: 'Reorder Python imports'
22+
- repo: https://github.com/PyCQA/docformatter
23+
rev: v1.5.1
24+
hooks:
25+
- id: docformatter
26+
name: 'Formats docstrings'
27+
args:
28+
- '--in-place'
29+
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
30+
rev: v4.1.0
31+
hooks:
32+
- id: trailing-whitespace
33+
- id: end-of-file-fixer
34+
- id: check-toml
35+
- repo: https://github.com/python/black
36+
rev: 22.8.0
37+
hooks:
38+
- id: black
39+
name: Uncompromising Code Formatter (black)

CODE_OF_CONDUCT.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
## Our Standards
10+
11+
Examples of behavior that contributes to a positive environment for our community include:
12+
13+
* Demonstrating empathy and kindness toward other people
14+
* Being respectful of differing opinions, viewpoints, and experiences
15+
* Giving and gracefully accepting constructive feedback
16+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the overall community
18+
19+
Examples of unacceptable behavior include:
20+
21+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
22+
* Trolling, insulting or derogatory comments, and personal or political attacks
23+
* Public or private harassment
24+
* Publishing others' private information, such as a physical or email address, without their explicit permission
25+
* Other conduct which could reasonably be considered inappropriate in a professional setting
26+
27+
## Enforcement Responsibilities
28+
29+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32+
33+
## Scope
34+
35+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36+
37+
## Enforcement
38+
39+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [email protected]. All complaints will be reviewed and investigated promptly and fairly.
40+
41+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42+
43+
## Enforcement Guidelines
44+
45+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46+
47+
### 1. Correction
48+
49+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50+
51+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52+
53+
### 2. Warning
54+
55+
**Community Impact**: A violation through a single incident or series of actions.
56+
57+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58+
59+
### 3. Temporary Ban
60+
61+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62+
63+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64+
65+
### 4. Permanent Ban
66+
67+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68+
69+
**Consequence**: A permanent ban from any sort of public interaction within the community.
70+
71+
## Attribution
72+
73+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
74+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
75+
76+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
77+
78+
[homepage]: https://www.contributor-covenant.org
79+
80+
For answers to common questions about this code of conduct, see the FAQ at
81+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Railsware Products Studio LLC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Official Mailtrap Python client
2+
3+
This Python package offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).
4+
5+
Quickly add email sending functionality to your Python application with Mailtrap.
6+
7+
## Installation
8+
9+
### Prerequisites
10+
11+
- Python version 3.6+
12+
13+
### Install package
14+
15+
```text
16+
pip install mailtrap
17+
```
18+
19+
## Usage
20+
21+
### Minimal
22+
23+
```python
24+
import mailtrap as mt
25+
26+
# create mail object
27+
mail = mt.Mail(
28+
sender=mt.Address(email="[email protected]", name="Mailtrap Test"),
29+
to=[mt.Address(email="[email protected]")],
30+
subject="You are awesome!",
31+
text="Congrats for sending test email with Mailtrap!",
32+
)
33+
34+
# create client and send
35+
client = mt.MailtrapClient(token="your-api-key")
36+
client.send(mail)
37+
```
38+
39+
### Full
40+
41+
```python
42+
import base64
43+
from pathlib import Path
44+
45+
import mailtrap as mt
46+
47+
welcome_image = Path(__file__).parent.joinpath("welcome.png").read_bytes()
48+
49+
mail = mt.Mail(
50+
sender=mt.Address(email="[email protected]", name="Mailtrap Test"),
51+
to=[mt.Address(email="[email protected]", name="Your name")],
52+
cc=[mt.Address(email="[email protected]", name="Copy to")],
53+
bcc=[mt.Address(email="[email protected]", name="Hidden Recipient")],
54+
subject="You are awesome!",
55+
text="Congrats for sending test email with Mailtrap!",
56+
html="""
57+
<!doctype html>
58+
<html>
59+
<head>
60+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
61+
</head>
62+
<body style="font-family: sans-serif;">
63+
<div style="display: block; margin: auto; max-width: 600px;" class="main">
64+
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">
65+
Congrats for sending test email with Mailtrap!
66+
</h1>
67+
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
68+
<img alt="Inspect with Tabs" src="cid:welcome.png" style="width: 100%;">
69+
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
70+
<p>Good luck! Hope it works.</p>
71+
</div>
72+
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
73+
<style>
74+
.main { background-color: white; }
75+
a:hover { border-left-width: 1em; min-height: 2em; }
76+
</style>
77+
</body>
78+
</html>
79+
""",
80+
category="Test",
81+
attachments=[
82+
mt.Attachment(
83+
content=base64.b64encode(welcome_image),
84+
filename="welcome.png",
85+
disposition=mt.Disposition.INLINE,
86+
mimetype="image/png",
87+
content_id="welcome.png",
88+
)
89+
],
90+
headers={"X-MT-Header": "Custom header"},
91+
custom_variables={"year": 2023},
92+
)
93+
94+
client = mt.MailtrapClient(token="your-api-key")
95+
client.send(mail)
96+
```
97+
98+
### Using email template
99+
100+
101+
```python
102+
import mailtrap as mt
103+
104+
# create mail object
105+
mail = mt.MailFromTemplate(
106+
sender=mt.Address(email="[email protected]", name="Mailtrap Test"),
107+
to=[mt.Address(email="[email protected]")],
108+
template_uuid="2f45b0aa-bbed-432f-95e4-e145e1965ba2",
109+
template_variables={"user_name": "John Doe"},
110+
)
111+
112+
# create client and send
113+
client = mt.MailtrapClient(token="your-api-key")
114+
client.send(mail)
115+
```
116+
117+
## Contributing
118+
119+
Bug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-python-sdk). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
120+
121+
### Development Environment
122+
123+
#### Clone the repo
124+
125+
```bash
126+
https://github.com/railsware/mailtrap-python-sdk.git
127+
cd mailtrap-python-sdk
128+
```
129+
130+
#### Install [tox](https://tox.wiki/en/latest/installation.html)
131+
`tox` is an environment orchestrator. We use it to setup local environments, run tests and execute linters.
132+
```bash
133+
python -m pip install --user tox
134+
python -m tox --help
135+
```
136+
137+
To setup virtual environments, run tests and linters use:
138+
```bash
139+
tox
140+
```
141+
It will create virtual environments with all installed dependencies for each available python interpreter (starting from `python3.6`) on your machine.
142+
By default, they will be available in `{project}/.tox/` directory. So, for instance, to activate `python3.11` environment, run the following:
143+
```bash
144+
source .tox/py311/bin/activate
145+
```
146+
147+
148+
## License
149+
150+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
151+
152+
## Code of Conduct
153+
154+
Everyone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md)

mailtrap/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .client import MailtrapClient
2+
from .exceptions import APIError
3+
from .exceptions import AuthorizationError
4+
from .exceptions import MailtrapError
5+
from .mail import Address
6+
from .mail import Attachment
7+
from .mail import BaseEntity
8+
from .mail import BaseMail
9+
from .mail import Disposition
10+
from .mail import Mail
11+
from .mail import MailFromTemplate

0 commit comments

Comments
 (0)