Skip to main content

SoWeMail library for Python 3

Project description

Build Status Codecov branch Code Climate Python Versions PyPI Version MIT licensed

This library allows you to quickly and easily use the SoWeMail Rest API via Python.

Table of Contents

Installation

Prerequisites

  • Python version 3.6+

  • You will need a SoWeMail account, signup

Setup Environment Variables

Mac

Update the development environment with your SOWEMAIL_API_KEY, for example:

echo "export SOWEMAIL_API_KEY='YOUR_API_KEY'" > sowemail.env
echo "sowemail.env" >> .gitignore
source ./sowemail.env

SoWeMail also supports local environment file .env. Copy or rename .env_sample into .env and update SOWEMAIL_API_KEY with your key.

Windows

Temporarily set the environment variable (accessible only during the current CLI session):

set SOWEMAIL_API_KEY=YOUR_API_KEY

Permanently set the environment variable (accessible in all subsequent CLI sessions):

setx SOWEMAIL_API_KEY "YOUR_API_KEY"

Install Package

pip install sowemail

Dependencies

Quick Start

Hello Email

The following is the minimum needed code to send an email with the /mail/send Helper (here is a full example):

With Mail Helper Class

import os
from sowemail import SoWeMailAPIClient
from sowemail.helpers.mail import Mail

message = Mail(
    from_email='from_email@example.com',
    to_emails='to@example.com',
    subject='Hello from SoWeMail',
    html_content='<strong>Simple email sending example using python\'s sowerest library</strong>')
try:
    sow_client = SoWeMailAPIClient(os.environ.get('SOWEMAIL_API_KEY'))
    response = sow_client.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(str(e))

The Mail constructor creates a personalization object for you. Here is an example of how to add it.

Without Mail Helper Class

The following is the minimum needed code to send an email without the /mail/send Helper (here is a full example):

import os
from sowemail import SoWeMailAPIClient

message = {
    'personalizations': [
        {
            'to': [
                {
                    'email': 'test@example.com'
                }
            ],
            'subject': 'Hello from SoWeMail'
        }
    ],
    'from': {
        'email': 'test@example.com'
    },
    'content': [
        {
            'type': 'text/plain',
            'value': 'Simple email sending example using python\'s sowerest library'
        }
    ]
}
try:
    sow_client = SoWeMailAPIClient(os.environ.get('SOWEMAIL_API_KEY'))
    response = sow_client.send(message)
    print(response.status_code)
    print(response.body)
    print(response.headers)
except Exception as e:
    print(str(e))

Thanks

This work were inspired and based on the awesome work done on sendgrid-python.

License

The MIT License (MIT)

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

sowemail-0.0.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file sowemail-0.0.1.tar.gz.

File metadata

  • Download URL: sowemail-0.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.7

File hashes

Hashes for sowemail-0.0.1.tar.gz
Algorithm Hash digest
SHA256 54236c000db4d1a3ebea6555564114fff6389dfff27d3d0c2b9c63e5cd63a066
MD5 2f701910cb7ee8274c691822f7b9632f
BLAKE2b-256 ee2208710ae533de9a39064ce7d3bc42279bd4c23c4671e71a68bcca987c620e

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