Smtp.com library for Python
Project description
Library for quickly and easily use the Smtp.com API v4 via Python.
This library provides support for Smtp.com public API SMTP.com API v4 documentation.
Installation
Python version 3.0+ required.
Install Package
pip install smtpcom
Getting Started
Examples for send an email via smtp.com API, more examples for sending (here):
With 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 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)
In directory examples you can find examples for usage all API calls.
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
smtpcom-1.1.0.tar.gz
(19.1 kB
view hashes)
Built Distribution
smtpcom-1.1.0-py3-none-any.whl
(24.8 kB
view hashes)