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.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

sowemail-0.0.2-py3.8.egg (8.2 kB view details)

Uploaded Egg

File details

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

File metadata

  • Download URL: sowemail-0.0.2.tar.gz
  • Upload date:
  • Size: 6.5 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.8.0

File hashes

Hashes for sowemail-0.0.2.tar.gz
Algorithm Hash digest
SHA256 50cae5a2165ff47acd98b6f4b0ee34b9fee35fbfe094a85fe920acc878e3e69d
MD5 fc66c3dfbc8761383c5e04633b8ffe50
BLAKE2b-256 9d103e707f90a7af5db1670153b77994f109d2f241b78acdce48d0bd39695bcc

See more details on using hashes here.

File details

Details for the file sowemail-0.0.2-py3.8.egg.

File metadata

  • Download URL: sowemail-0.0.2-py3.8.egg
  • Upload date:
  • Size: 8.2 kB
  • Tags: Egg
  • 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.8.0

File hashes

Hashes for sowemail-0.0.2-py3.8.egg
Algorithm Hash digest
SHA256 7c47915271840d2d1133e30cfa1884674058a699dc1323ece9cb8d88d3f32f54
MD5 7aeddf7dbe2fe8c8a7b4cd2b13060e66
BLAKE2b-256 efaeb0df69627e5725be2cc77fc2927e3df481ad8f7c99aff983418db68399ec

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