Skip to main content

Smtp.com library for Python

Project description

Smtp.com logo

Code style: black MIT licensed

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


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.1.tar.gz (19.2 kB view hashes)

Uploaded Source

Built Distribution

smtpcom-1.1.1-py3-none-any.whl (24.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page