Python bindings for Apostle.io.
pip install apostle
You will need to provide your apostle domain key to send emails. You can either place this value into your OS environment as APOSTLE_DOMAIN_KEY
, or specify it in your code.
apostle.domain_key = 'Your domain key'
Sending an email is easy, a minimal example may look like this.
apostle.deliver('welcome_email', {'email': 'mal@apostle.io'})
You can pass any information that your Apostle.io template might need.
order = {
'items': ['Widget frame', 'Widget chain', 'Widget seat'],
'id': "abc123"
}
apostle.deliver('order_complete', {
'email': 'mal@apostle.io',
'replyTo': 'support@apostle.io',
'order': order
})
m = apostle.Mail("payment_complete", {"email": 'mantesh@apostle.io', 'name': 'Mantesh'})
m.add_attachment("receipt.txt", "receipt content")
queue = apostle.get_queue()
queue.add(m)
queue.deliver()
You can send multiple emails at once by using a queue. If any of the emails fail validation, no emails will be sent.
queue = apostle.Queue()
queue.add('welcome_email', {'email': 'mal@apostle.io'})
queue.add('order_email', {'email': 'mal@apostle.io', 'order': order})
queue.deliver()
Failure to deliver will result in an exception being raised. All exceptions are namespaced under apostle.exceptions
.
ValidationError
- Validation failed. One or more emails did not have a template id, or email address set (see error text).UnauthorizedError
(HTTP 401) – Authorization failed. Either no domain key, or an invalid domain key was supplied.ForbiddenError
(HTTP 403) – The domain key you used was not authorized to perform the action you have requested.UnprocessableEntityError
(HTTP 422) – Unprocessable entitity. An invalid payload was supplied, usually a missing email or template id, or no recipients key.apostle.py
should validate before sending, so it is unlikely you will see this response.ServerError
(HTTP >= 500) – Server error. Something went wrong at the Apostle API, you should try again with exponential backoff.DeliveryError
– Any response code that is not covered by the above exceptions.
Created with ♥ by Mal Curtis (@snikchnz)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request