Skip to main content

A simple mailer for web forms

Project description

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 mail to a specific email address.

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

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.

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

SMTP_PORT

The port number of the SMTP server at SMTP_HOST.

Example: 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

SMTP_PASSWORD

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

Example: rosebud20

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

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.

Example: my-mail

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/my-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.

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

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.

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

simple-mailer-0.12.0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

simple_mailer-0.12.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file simple-mailer-0.12.0.tar.gz.

File metadata

  • Download URL: simple-mailer-0.12.0.tar.gz
  • Upload date:
  • Size: 13.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/40.8.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for simple-mailer-0.12.0.tar.gz
Algorithm Hash digest
SHA256 e85d92964a72ba90a032d923e78636df0645a3511e5112decf2c0bfc39de0eaa
MD5 b1119eeaad60f6851dc876dad03a0cff
BLAKE2b-256 e0b68dfd1fcc6656d2e1859802f53fd940ce82e46a48c42689b998cbe690651c

See more details on using hashes here.

File details

Details for the file simple_mailer-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: simple_mailer-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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/40.8.0 requests-toolbelt/0.8.0 tqdm/4.46.0 CPython/3.7.5

File hashes

Hashes for simple_mailer-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 212ead06a199d15bab8f3158dc82d640f81d30d0a33ee9ae823e5c37a33b7886
MD5 c5bbc2888bb81ffcf6c003ea4a360eda
BLAKE2b-256 58f475d83c3fe536cae017d8f8e6995d1c4dff905d6caf45d1e37558df489131

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page