![Smtp.com logo](https://github.com/smtpcom/smtpcom-python/raw/HEAD/smtpcom-logo.png)
![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)
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,
)
smtpcom = SMTPAPIClient(api_key=os.environ.get("SMTPCOM_API_KEY"))
channel = "some_channel_example"
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"
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.