Skip to main content

Simple Mailer

Build Status PyPi version t

A simple Python mailer program that can be run in the WSGI environment of a shared hosting provider.

This program provides a web resource that can be used by an HTML web form to send a plain text email to a specific email address. HTML mail are not supported.

Python version: 3.7+

Features:

  • Can be triggered by a WSGI call or run standalone as a daemon
  • Configurable using environment variables
  • Captcha support (Recaptcha v3 for now)
  • Customizable email template
  • Easy to setup

Installation

Generic Shared Hosting

  1. Install the package, e.g. using pip install simple-mailer
  2. Copy over the wsgi/passenger_wsgi.py to the appropriate folder and rename accordingly
  3. Configure the environment variables, listed below, as needed

More information, including hosting provider specific instructions, can be found on the Wiki.

Namecheap

See this blog post.

Configuration

All configuration is done using environment variables.

SMTP_HOST

The hostname of the SMTP server that will send the email.

Example: smtp.example.com

Default: localhost

SMTP_PORT

The port number of the SMTP server at SMTP_HOST.

Default: 465

USE_TLS

Secure the connection to the SMTP server using TLS. Highly recommended.

Default: true

SMTP_USERID

The id of the SMTP user account on the SMTP server at SMTP_HOST.

Example: mailer@example.com

Default: An empty string.

SMTP_PASSWORD

The password of the SMTP user account on the SMTP server at SMTP_HOST.

Example: rosebud20

SMTP_TIMEOUT

The maximum number of seconds allowed for a SMTP connection to be established.

Default: 5

TO_ADDRESS

The recipient email address that will receive the email.

Example: orders@example.net

FROM_ADDRESS

The email address of the sender that will appear in the email that will be sent.

Example: mailer@example.com

REPLY_TO_FIELD

The form field that will be used to populate the Reply-to field of the email.

Default: An empty string

Example: email

MAIL_SUBJECT

The subject of every sent email.

You can use Jinja2 template tags here, just like the email body. The variables in the template context are:

  • data, containing all the fields that were sent (and passed the filters)
  • metadata, containing fields for: client_ip (the originating IP address), origin (the origin of the request, e.g. the page with the form), mailer_url (the URL of the mailer endpoint that processed the request)

Example: An order for {{data.goods} was sent from IP {{metadata.client_ip}}

Default: An empty string.

MAIL_TEMPLATE_PATH

The filesystem path to the email template file that will be used for the outgoing email.

You can use Jinja2 template tags in the email template. The variables that will be made available in the template context are:

  • data, containing all the fields that were sent (and passed the filters)
  • metadata, containing fields for: client_ip (the originating IP address), origin (the origin of the request, e.g. the page with the form), mailer_url (the URL of the mailer endpoint that processed the request)

Example: /home/myuser/templates/mail.txt

Default: The default template will be used.

MAILER_PATH

The path of the URL where the mailer resource will be available.

Default: mail

If the root path of this application has been made available at https://api.example.com/simple-mailer, email will need to be POSTed to https://api.example.com/simple-mailer/mail

CAPTCHA_TYPE

The captcha protocol to use. Possible values are: recaptchav3

Example: recaptchav3

Default: An empty string (no captcha system will be used - not recommended)

Note: the relevant captcha field in the POST, e.g. g-captcha-response, will be removed from the data that will be sent by email.

CAPTCHA_SECRET

The secret used to validate the request using a given secret.

Example: d0n0tsh4r3m3

Default: An empty string.

CAPTCHA_VERIFY_URL

The URL where challenge responses regarding the captcha can be verified, if required.

Example: https://www.google.com/recaptcha/api/siteverify

Default: An empty string.

REDIRECT_URL

If set, redirect the client to the given URL. If not, set a 200 OK response will be returned. The following template tags can be used: {{ REFERER }}, to use the value of the Referer (sic) field of the request, and {{ ORIGIN }}, to use the value of the Origin field of the request.

Example: https://www.example.org/thank-you

Example: {{ REFERER }}

Default: An empty string

FIELDS_EXCLUDED

A list of fields in the POST request to exclude from the email. Fields are comma separated. These fields take precedence over FIELDS_INCLUDED, i.e. if a field is mentioned here it will be excluded even if it is listed in FIELDS_INCLUDED.

Example: secret_field1,secret_field2

Default: An empty string (no fields are excluded)

FIELDS_INCLUDED

A list of fields in the POST request to include in the email. Fields are comma separated. All other fields will be ignored, but only if they are not also mentioned in FIELDS_EXCLUDED

Example: secret_field1,secret_field2

Default: An empty string (no fields are excluded)

Note: captcha keys are automatically included.

ENABLE_DEBUG

Enable the debug resource. This provides various diagnostic information.

The resource will be made available at DEBUG_PATH

Default: false

Note: Only enable it when you're trying to debug a problem, since it will expose your configuration variables and is expensive to render.

DEBUG_PATH

The path where the debug resource will be made available.

Default: /debug

LOG_LEVEL

The log level, from a choice of: DEBUG, INFO WARN, ERROR, and CRITICAL.

Default: WARN

Metadata

Release files for simple-mailer 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-mailer 1.1.1
File Size Uploaded Provenance Actions
simple-mailer-1.1.1.tar.gz 14.8 kB Without provenance Details for simple-mailer-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for simple-mailer 1.1.1
File Interpreter ABI Platform Actions
simple_mailer-1.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for simple_mailer-1.1.1-py2.py3-none-any.whl

Total release size: 29.4 kB

Release files / simple-mailer-1.1.1.tar.gz

Download URL simple-mailer-1.1.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
591cedd9a8909a0c2dc6a354bf4c9e78c16ec5356ac9f6b7d0d2b316527d9d84
BLAKE2b-256 checksum
How to use checksums
b71cd092a6575982c5d2ab9644a5b9135685d0b7e95402a0f847e958f49ae879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release files / simple_mailer-1.1.1-py2.py3-none-any.whl

Download URL simple_mailer-1.1.1-py2.py3-none-any.whl
Size 14.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b21099361d2911f7e914bf9a4c2ed797c628991e601a8283eceac92e96dee6e3
BLAKE2b-256 checksum
How to use checksums
8ab7abc41c24e1da7f43ae9ad3ba097480d86bbbfec49d98f83cb1097ef29aac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Security for simple-mailer 1.1.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page