Coresender API for sending email
Project description
Coresender Python SDK
This is the officially supported Python library for Coresender. It allows you to quickly and easily integrate with our API and improve your email deliverability.
Prerequisites
- Python version 3.6+
- The Coresender service. You can start with a free 100 emails/month developer plan and move to one of our pricing plans when you're done.
Installation
Run the following command to get started:
python3 -m pip install coresender
Usage
Here's how to send an email using the SDK:
import asyncio
import uuid
import coresender
async def main():
coresender.init(
sending_account_id='<<INSERT CORESENDER SENDING ACCOUNT ID>>',
sending_account_key='<<INSERT CORESENDER SENDING ACCOUNT API KEY>>',
# debug=True # if True, then show some logs on stderr, or use `CORESENDER_DEBUG` environment variable
)
# EXAMPLE 1 – Recommended
rq = coresender.SendEmail()
custom_id = str(uuid.uuid4())
rq.add_to_batch(
from_email='sender@example.com',
from_name='sender',
to_email='recipient-1@example.net',
to_name='Recipient-1',
reply_to_email='reply-address@example.com',
reply_to_name='sender',
subject='Coresender test ' + custom_id,
body_text='Hello,\nWorld!',
body_html='<strong>Hello</strong>,<br>World!',
custom_id=str(custom_id),
track_opens=True,
track_click=True
)
custom_id = str(uuid.uuid4())
rq.add_to_batch(
from_email='sender@example.com',
from_name='sender',
to_email='recipient-2@example.net',
to_name='Recipient-2',
subject='Coresender test ' + custom_id,
body_text='Hello,\nWorld!',
body_html='<strong>Hello</strong>,<br>World!',
custom_id=str(custom_id),
track_opens=True,
track_click=True
)
rsp = await rq.execute()
for i in rsp:
print(i)
# Example 2 – For the simplest needs
custom_id = str(uuid.uuid4())
rsp = await rq.simple_email(
from_email='sender@example.com',
to_email='recipient-1@example.net',
subject='Coresender test ' + custom_id,
body='<strong>Hello</strong>,<br>World!',
body_type=coresender.BodyType.html
)
print(rsp)
if __name__ == '__main__':
asyncio.run(main())
Environment variables
Instead of putting sending account credentials directly in the code, you may want to put them in your environment variables:
CORESENDER_SENDING_API_ID=<<INSERT CORESENDER SENDING ACCOUNT ID>>
CORESENDER_SENDING_API_KEY=<<INSERT CORESENDER SENDING ACCOUNT API KEY>>
The library will detect it automatically and use the credentials stored as environment variables.
You can also use CORESENDER_DEBUG environment variable to toggle debug logs.
Response
The result of a method call is, by default, a domain object.
Every response object has http_status property that contains API HTTP response code. Other properties depend on the method you use.
SendEmail.execute
The response is an instance of responses.SendEmail. Because this method allows for sending many emails with one API request, the SendEmail.all_accepted property lets you quickly check if all messages were accepted. If its value is false it means you have to further check for rejected messages.
responses.SendEmail is also an iterator that contains information about the status (and possible errors) of every message from the batch. Items are instances of responses.SendEmailResponse, containing data returned by the API.
SendEmail.simple_email
As this method allows for sending just one email, without batching, the response is simply an instance of responses.SendEmailResponse.
Debugging
For debug purposes there is a flag in Coresender.init method (look at Usage section above). If you enable debug, the library will print out logs to STDERR by default. You can configure it further by fetching coresender log handler:
import logging
logger = logging.getLogger('coresender')
For more information about loggers, take a look at official documentation of the logging module.
Development
For installing dependencies use Pipenv:
pipenv install --dev
pipenv shell
Contribute
The Coresender PHP SDK is an open-source project released under MIT license. We welcome any contributions!
You can help by:
- Writing new code
- Creating issues if you find problems
- Helping others with their issues
- Reviewing PRs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coresender-1.1.1.tar.gz.
File metadata
- Download URL: coresender-1.1.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9981e8771182cb6ecf621a297e3de2f3ca6b1b36e3dfc752cbed6530b33eb0b
|
|
| MD5 |
59e9c7832496e101606c2eb3888e17b2
|
|
| BLAKE2b-256 |
b92379cb95a8ceeeec3914579b3190fbec42c4ca0e3a9cbfd3de2b9e6a8d8593
|
File details
Details for the file coresender-1.1.1-py3-none-any.whl.
File metadata
- Download URL: coresender-1.1.1-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f06e4e3f41ca5dbfc931f118fc376435e751423f2f16b3d11064ac6ba5e81d89
|
|
| MD5 |
c3dd1a7692a5717adf45c97796f51ee1
|
|
| BLAKE2b-256 |
29124e20d148b255970cb5683539666c7467ea1cd98670d0dbba191bb724e452
|