Send HIPAA compliant transactional email with Python

Featured image

Share this article

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]>"
            },
            "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.
Author Photo

About the author

Hoala Greevy

Founder of Paubox. Kayak fishing when I can. Native Hawaiian CEO.

Read more by Hoala Greevy

Get started with
end-to-end protection

Bolster your organization’s security with healthcare’s most trusted HIPAA compliant email solution

The #1-rated email encryption 
and security software on G2

G2 Badge: Email Encryption Leader Fall 2022
G2 Badge: Security Best Usability Fall 2022
G2 Badge: Encryption Momentum Leader Fall 2022
G2 Badge: Security Best Relationship Fall 2022
G2 Badge: Security Users Most Likely to Recommend Fall 2022
G2 Badge: Email Gateway Best Relationship Fall 2022
G2 Badge: Email Gateway Best Meets Requirements Fall 2022
G2 Badge - Users Most Likely to Recommend Summer 2022
G2 Badge: Email Gateway Best Results Fall 2022
G2 Badge: Email Gateway Best Usability Fall 2022
G2 Badge: Email Gateway Best Support Fall 2022
G2 Badge: Email Gateway Easiest To Use Fall 2022
G2 Badge: Email Gateway Easiest Setup Fall 2022
G2 Badge: Email Gateway Easiest Admin Fall 2022
G2 Badge: Email Gateway Easiest to do Business with Fall 2022
G2 Badge: Email Gateway Highest User Adoption 2022
G2 Badge: Email Gateway High Performer Fall 2022
G2 Badge: Email Gateway Momentum Leader Fall 2022
G2 Badge: Email Gateway Most Implementable Fall 2022
G2 Badge: Email Gateway Users Most Likely to Recommend Fall 2022