Skip to the main content.
Talk to sales Start for free
Talk to sales Start for free

2 min read

Send HIPAA compliant transactional email with Python

Send HIPAA compliant transactional email with Python

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 = ["recipient@example.com"]
from_ = "sender@yourdomain.com"
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": [
                "recipient@example.com"
            ],
            "headers": {
                "subject": "Testing!",
                "from": "sender@yourdomain.com"
            },
            "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 = ["recipient@example.com"]
from_ = "sender@yourdomain.com"
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': 'replies@yourdomain.com',
    'bcc': 'recipient2@example.com'
}
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": [
                "recipient@example.com"
            ],
            "bcc": ["recipient2@example.com"],
            "headers": {
                "subject": "Testing!",
                "from": "Sender <sender@yourdomain.com>",
                "reply-to": "Reply-to <replies@yourdomain.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.
 

Subscribe to Paubox Weekly

Every Friday we'll bring you the most important news from Paubox. Our aim is to make you smarter, faster.