Package: simple-mailer
Simple MailerA 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 daemonConfigurable using environment variablesCaptcha support (Recaptcha v3 for now)Customizable email templateEasy to setupInstallationGeneric Shared HostingInstall the package, e.g. usingpip install simple-mailerCopy over thewsgi/passenger_wsgi.pyto the appropriate folder and rename
accordinglyConfigure the environment variables, listed below, as neededMore information, including hosting provider specific instructions, can be
found on theWiki.NamecheapSee thisblog post.ConfigurationAll configuration is done using environment variables.SMTP_HOSTThe hostname of the SMTP server that will send the email.Example:smtp.example.comDefault:localhostSMTP_PORTThe port number of the SMTP server atSMTP_HOST.Default:465USE_TLSSecure the connection to the SMTP server using TLS. Highly recommended.Default:trueSMTP_USERIDThe id of the SMTP user account on the SMTP server atSMTP_HOST.Example:mailer@example.comDefault: An empty string.SMTP_PASSWORDThe password of the SMTP user account on the SMTP server atSMTP_HOST.Example:rosebud20SMTP_TIMEOUTThe maximum number of seconds allowed for a SMTP connection to be established.Default: 5TO_ADDRESSThe recipient email address that will receive the email.Example:orders@example.netFROM_ADDRESSThe email address of the sender that will appear in the email that will
be sent.Example:mailer@example.comREPLY_TO_FIELDThe form field that will be used to populate the Reply-to field of the email.Default: An empty stringExample:emailMAIL_SUBJECTThe 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_PATHThe 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.txtDefault: The default template will be used.MAILER_PATHThe path of the URL where the mailer resource will be available.Default:mailIf the root path of this application has been made available athttps://api.example.com/simple-mailer, email will need to be POSTed tohttps://api.example.com/simple-mailer/mailCAPTCHA_TYPEThe captcha protocol to use. Possible values are:recaptchav3Example:recaptchav3Default: 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_SECRETThe secret used to validate the request using a given secret.Example:d0n0tsh4r3m3Default: An empty string.CAPTCHA_VERIFY_URLThe URL where challenge responses regarding the captcha can be verified, if
required.Example:https://www.google.com/recaptcha/api/siteverifyDefault: An empty string.REDIRECT_URLIf 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-youExample:{{ REFERER }}Default: An empty stringFIELDS_EXCLUDEDA list of fields in the POST request to exclude from the email. Fields are
comma separated. These fields take precedence overFIELDS_INCLUDED, i.e. if
a field is mentioned here it will be excluded even if it is listed inFIELDS_INCLUDED.Example:secret_field1,secret_field2Default: An empty string (no fields are excluded)FIELDS_INCLUDEDA 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 inFIELDS_EXCLUDEDExample:secret_field1,secret_field2Default: An empty string (no fields are excluded)Note: captcha keys are automatically included.ENABLE_DEBUGEnable the debug resource. This provides various diagnostic information.The resource will be made available atDEBUG_PATHDefault:falseNote: Only enable it when you're trying to debug a problem,
since it will expose your configuration variables and is expensive to render.DEBUG_PATHThe path where the debug resource will be made available.Default:/debugLOG_LEVELThe log level, from a choice of:DEBUG,INFOWARN,ERROR, andCRITICAL.Default:WARN