Send HIPAA compliant transactional email with Python

Send HIPAA Compliant Transactional Email with Python - Paubox

Python Library for Paubox Email API

The Paubox Python wrapper allows you to construct and send secure, HIPAA compliant messages. This package is the official Python wrapper for the Paubox Email API.

The Paubox Email API allows your application to send secure, HIPAA compliant email via Paubox and track deliveries and opens.

See Related: Python 3 SDK added to Paubox Email API

See Also: Why Healthcare Businesses Choose the Paubox Email API

Installation


Getting Paubox Email API Credentials

You will need to have a Paubox account. You canĀ sign up here.

Once you have an account, follow the instructions on the Rest API dashboard to verify domain ownership and generate API credentials.

Setup Environment Variables

$ echo "export PAUBOX_API_KEY='YOUR_API_KEY'" > .env
$ echo "export PAUBOX_HOST='https://api.paubox.net/v1/YOUR_ENDPOINT_NAME'" >> .env
$ echo ".env" >> .gitignore
$ source .env

Install Package

$ pip install paubox

Dependencies

Requests

Usage


Sending Messages with the Paubox Mail Helper

Sending via Paubox is easy. This is the minimum content needed to send an email.

import paubox
from paubox.helpers.mail import Mail

paubox_client = paubox.PauboxApiClient()
recipients = ["[email protected]"]
from_ = "[email protected]"
subject = "Testing!"
content = {"text/plain": "Hello World!"}
mail = Mail(from_, subject, recipients, content)
response = paubox_client.send(mail.get())
print(response.status_code)
print(response.headers)
print(response.text)

Sending Messages without the Mail Helper Class

import paubox

paubox_client = paubox.PauboxApiClient()
mail = {
    "data": {
        "message": {
            "recipients": [
                "[email protected]"
            ],
            "headers": {
                "subject": "Testing!",
                "from": "[email protected]"
            },
            "content": {
                "text/plain": "Hello World!",
            }
        }
    }
}
response = paubox_client.send(mail)
print(response.status_code)
print(response.headers)
print(response.text)

Sending Messages with all available headers

Using Mail Class Helper

import paubox
import base64
from paubox.helpers.mail import Mail

paubox_client = paubox.PauboxApiClient()
recipients = ["[email protected]"]
from_ = "[email protected]"
subject = "Testing!"
attachment_content = base64.b64encode("Hello World!")
content = {
    "text/plain": "Hello World!",
    "text/html": "

Hello World!

"
}
optional_headers = {
    "attachments": [{
        "fileName": "the_file.txt",
        "contentType": "text/plain",
        "content": attachment_content
    }],
    'reply_to': '[email protected]',
    'bcc': '[email protected]'
}
mail = Mail(from_, subject, recipients, content, optional_headers)
response = paubox_client.send(mail.get())
print(response.status_code)
print(response.headers)
print(response.text)

Without the Mail Class Helper

import paubox
import base64

paubox_client = paubox.PauboxApiClient()
attachment_content = base64.b64encode("Hello World!")
mail = {
    "data": {
        "message": {
            "recipients": [
                "[email protected]"
            ],
            "bcc": ["[email protected]"],
            "headers": {
                "subject": "Testing!",
                "from": "Sender <[email protected]>",
                "reply-to": "Reply-to <[email protected]urdomain.com>"
            },
            "content": {
                "text/plain": "Hello World!",
                "text/html": "

Hello World!

"
            },
            "attachments": [{
                    "fileName": "the_file.txt",
                    "contentType": "text/plain",
                    "content": attachment_content
            }]
        }
    }
}
response = paubox_client.send(mail)
print(response.status_code)
print(response.headers)
print(response.text)

Checking Email Dispositions

The SOURCE_TRACKING_ID of a message is returned in the response.text of your send request. Use response.to_dict to access the response text as a dictionary.

import paubox

paubox_client = paubox.PauboxApiClient()
disposition_response = paubox_client.get("SOURCE_TRACKING_ID")
print(disposition_response.status_code)
print(disposition_response.headers)
print(disposition_response.text)

Contributing


Bug reports and pull requests are welcome on GitHub at https://github.com/Paubox/paubox-python.

Try the Paubox Email API for FREE today.

About the author

Hoala Greevy

Founder CEO Paubox. Kayak fishing when I can.

Read more by Hoala Greevy

Get started with
end-to-end protection

Bolster your organization's security with state-of-the-art email encryption and inbound email security.

Highest rated HIPAA compliant email solution on G2

EmailEncryption BestMeetsRequirements MeetsRequirements
SecureEmailGateway MostImplementable Total
SecureEmailGateway Leader Leader
SecureEmailGateway EasiestToUse EaseOfUse
SecureEmailGateway EasiestAdmin EaseOfAdmin
SecureEmailGateway BestUsability Total
SecureEmailGateway BestResults Total
SecureEmailGateway BestRelationship Total
EmailEncryption UsersMostLikelyToRecommend Nps
EmailEncryption MomentumLeader Leader
SecureEmailGateway BestSupport Mid Market QualityOfSupport
EmailEncryption BestMeetsRequirements MeetsRequirements
SecureEmailGateway MostImplementable Total
SecureEmailGateway Leader Leader
SecureEmailGateway EasiestToUse EaseOfUse
SecureEmailGateway EasiestAdmin EaseOfAdmin
SecureEmailGateway BestUsability Total
SecureEmailGateway BestResults Total
SecureEmailGateway BestRelationship Total
EmailEncryption UsersMostLikelyToRecommend Nps
EmailEncryption MomentumLeader Leader
SecureEmailGateway BestSupport Mid Market QualityOfSupport