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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

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

Hashes for smtpcom-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d7b9d645c5638403626c082e5ebffb4bb14dbad8f24cbe590e10f7706d2f9eac
MD5 460604ebdbe09f1669b23ec2a8a68e68
BLAKE2b-256 fe50104b835e2bf68a66877bf9a4530b4a0bd1a99ba57c5e0b00ece7ed882f6a

See more details on using hashes here.

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

Hashes for smtpcom-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ca0211139337427cf37171fa27762707ba12cc2631ce0ed531ca7df00373c39
MD5 a2f0c299087c067e91699f46f134f63f
BLAKE2b-256 11316655213e996a867ba703d97fbac0040c8b4c4146ade375f027eaf74e092e

See more details on using hashes here.

Supported by

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