Smtp.com library for Python
Project description
Python Library for Quick and Easy Use of the SMTP.com v4 API.
This library provides support for the SMTP.com public API SMTP.com API v4 documentation.
Installation
Python version 3.0+ required.
Install Package
pip install smtpcom
Getting Started
Examples how to send an email via SMTP.com API, more examples for sending can be found here:
With a Helper Class
import os
from smtpcom import SMTPAPIClient
from smtpcom.helpers.mail import (
Mail,
From,
To,
Subject,
Channel,
Content,
)
# getting api key from env variable SMTPCOM_API_KEY that was present
smtpcom = SMTPAPIClient(api_key=os.environ.get("SMTPCOM_API_KEY"))
channel = "some_channel_example"
# send with html content
mail = Mail(
from_email=From("test_from@example.com"),
to_emails=To("test_to@example.com"),
subject=Subject("Test"),
channel=Channel(channel),
contents=Content(
content="<html>\n<head></head>\n<body>\nSome HTML content\n</body>\n</html>\n",
content_type="text/html",
encoding="quoted-printable",
),
)
response = smtpcom.send(mail)
print(response.status_code)
print(response.body)
print(response.headers)
Without a Helper Class
import os
from smtpcom import SMTPAPIClient
smtpcom = SMTPAPIClient(api_key=os.environ.get("SMTPCOM_API_KEY"))
channel = "some_channel_example"
# send with raw body
raw_mail_body = {
"channel": channel,
"recipients": {"to": [{"address": "test_to@example.com"}]},
"originator": {"from": {"address": "test_from@example.com"}},
"subject": "Test",
"body": {
"parts": [
{
"content": "<html>\n<head></head>\n<body>\nSome HTML content\n</body>\n</html>\n",
"type": "text/html",
"encoding": "quoted-printable",
}
]
},
}
response = smtpcom.send(raw_mail_body)
print(response.status_code)
print(response.body)
print(response.headers)
Additional Examples
You can find additional examples covering all API calls in the examples folder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smtpcom-1.1.1.tar.gz.
File metadata
- Download URL: smtpcom-1.1.1.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7b9d645c5638403626c082e5ebffb4bb14dbad8f24cbe590e10f7706d2f9eac
|
|
| MD5 |
460604ebdbe09f1669b23ec2a8a68e68
|
|
| BLAKE2b-256 |
fe50104b835e2bf68a66877bf9a4530b4a0bd1a99ba57c5e0b00ece7ed882f6a
|
File details
Details for the file smtpcom-1.1.1-py3-none-any.whl.
File metadata
- Download URL: smtpcom-1.1.1-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ca0211139337427cf37171fa27762707ba12cc2631ce0ed531ca7df00373c39
|
|
| MD5 |
a2f0c299087c067e91699f46f134f63f
|
|
| BLAKE2b-256 |
11316655213e996a867ba703d97fbac0040c8b4c4146ade375f027eaf74e092e
|