This module provides an interface for the smtprelay server that allows it to be used as a logger or just to send emails.
smtprelay is designed to act as a message queue for sending e-mails so that rate limiting and authentication can be implemented in one place.
Configuration
Configuration is done via Zirconium, which allows for you to use your configuration language of choice. The example configuration below is given in TOML. Note that you must install the toml package for versions of Python where it is not built-in.
[smtp_relay]
end_point = "http://server:port/send" # Mandatory, put in the path to your smtprelay server here.
bearer_token = "blahblah" # Mandatory, put in your secret token here from the relay server.
default_send_group = "" # Optional, specify a send group to be applied to all messages unless one is specified in code.
default_send_from = "" # Optional, specify a sender e-mail here for all messages unless one is provided in code.
retry_file = "" # Optional, specify a path to a file that will be used to store messages when the relay server cannot be contacted.
show_errors = true # Change to false to hide the printed errors when connections to the relay server fail
request_timeout = 2.5 # Change the timeout for the requests module here (default is 2.5)
cap_on_retry = 50 # Change the maximum number of e-mails that will be send during a retry attempt.
Automatic Retries
This package allows for e-mails to be saved to a file if the smtprelay server is not available. To use this option, you must first set the retry_file to a file path in the configuration. You can then schedule the resend using either the entry point or by calling the module in cron.d or Windows task manager:
# Make sure you're in the right venv and that you execute this from the proper
# working directory for where you've located the configuration files.
python -m smtprelayapi
# OR
smtprelayapi-resend
Usage
In this example, we simply queue up a message to be sent. The send_group parameter is a simple text string
that is recorded on the server side so that the origin of messages can be tracked.
from autoinject import injector
from smtprelayapi import RelayClient
@injector.inject
def send_an_email(rc: RelayClient = None):
rc.send_email(
subject="Extended Warranty",
plain_message="We've been trying to reach you about your car's extended warranty.",
html_message="<p>We've been trying to reach you about your car's <strong>extended warranty</strong>.</p>",
from_email="scammer@example.com",
to_emails="adam.undergrove@example.com",
bcc_emails="head.scammer@example.com",
send_group="warranty-scams"
)
An implementation of logging.Handler is also provided for simplicity to integrate with the logging module.
from smtprelayapi import RelayHandler
import logging
handler = RelayHandler(
subject="Application Log: myapplication: %{levelname}!",
format_subject=True,
toaddrs="admin@example.com",
ccaddrs="manager@example.com",
send_group="myapplication-errors",
level=logging.WARNING
)
logging.getLogger().addHandler(handler)
Metadata
Release files for smtprelayapi 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smtprelayapi-1.0.0.tar.gz | 8.1 kB | Without provenance | Details for smtprelayapi-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smtprelayapi-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for smtprelayapi-1.0.0-py3-none-any.whl |
Total release size: 16.1 kB
Release files / smtprelayapi-1.0.0.tar.gz
| Download URL | smtprelayapi-1.0.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3de5136f567e591c4ea925037b5691734aca90655ad757465c7d77d63c2c7afa
|
|
BLAKE2b-256 checksum How to use checksums |
22e1b8ed953e7d6712acbe5e10026992c9928374b1287449595ee81e6ad8d095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / smtprelayapi-1.0.0-py3-none-any.whl
| Download URL | smtprelayapi-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b8c942c67f769a028e61ea9f45f44f5860d0471aeafe43888f32dfa41287caf
|
|
BLAKE2b-256 checksum How to use checksums |
dbf9dfaa3b602d3199a669bdd7cab2c4ecb0ca311a5af6d6c0e3d46590f01bfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for smtprelayapi 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.