#send-email #web-dev #form-data #env-var #web-apps #backend-server

app reformulate

reformulate is a standalone server that listens for web form data submissions

4 releases (breaking)

0.4.0 Nov 29, 2023
0.3.0 Oct 31, 2023
0.2.0 Apr 1, 2023
0.1.0 Mar 21, 2023

#355 in HTTP server

Download history 8/week @ 2023-11-23 1/week @ 2023-11-30 27/week @ 2024-02-22 71/week @ 2024-02-29

98 downloads per month

MIT license

29KB
404 lines

ReFormulate

A backend server application that listens for web form submissions, implemented with the actix-web framework. Minimum supported rust version (MSRV) is 1.62.1.

Configuration

Configuration is currenly very simple and only two environment variables need to be set: FORMULATE_DESTINATION_EMAIL and FORMULATE_SENDING_EMAIL.

The "destination email" will be the email address you wish the form submissions to be sent to.

The "sending email" is the address the emails will come from when delivered to your inbox. It is meant to be a stable address which you can use to filter your form submission emails. This "sending email" will be used in the email's 'From:' header.

The 'Reply-To' address will be the email address submitted by the form's user.

Relaying email

Another pair of environment variables, FORMULATE_MAIL_RELAY_HOST and FORMULATE_MAIL_RELAY_PORT, are optional. These are used if relaying emails via the SMTP protocol is desired.

If set FORMULATE_MAIL_RELAY_HOST defines the hostname for the relaying mail server.

FORMULATE_MAIL_RELAY_PORT meanwhile always defaults to port 25, but allows users to define an alternate port which the mail relay is listening on.

Accepted Form Fields

It accepts the following parameters, most of which are required:

  • email: The email address of the form sender. This will be set as the 'Reply-To' address in the sent email.
  • from_site: The URL of the site which the form is submitted from. Can also be submitted as site, website, or location. Alternatively, for url-encoded form submissions, this can be set to the URL of the page the user should be redirected to if the form was submitted successfully. This form field can be hidden and set via JavaScript before submission.
  • full_name: The name the form sender would like to use in the sent email. This will be used as the email sender name. Can also be submitted as fullname, or fullName.
  • message: The message body of the sent email
  • subject: (optional) The title of the email. A default subject will be used if this is not provided.
  • redirect: (optional) Used to indicate if user wants to be redirected to from_site URL. When submitted via JSON will need to be sent as a boolean value.

After processing form submissions it responds with a message containing appropriate HTTP status codes, indicating success or failure.

Successful URL-encoded submissions will be redirected to the URL defined in the from_site field when the redirect value is true. If redirect is omitted, or false, a message with an appropriate HTTP status is provided. On failure, a user readable error is sent bacl, with a relevant HTTP status.

JSON form submissions receive a JSON response with appropriate success or failure messages and HTTP statuses.

Blocking SPAM

Rudimentary SPAM blocking functionality is now available in reformulate.

SPAM blocklist

Optional blocklist functionality can be enabled by defining the FORMULATE_SPAM_BLOCKLIST environment variable.

FORMULATE_SPAM_BLOCKLIST should be a comma separated list of strings, formatted as domain names. These strings will be searched for in the form's message body and—if any match is found—result in form processing ending early. An error will be returned, with a message indicating the form submission is suspected SPAM. e.g. FORMULATE_SPAM_BLOCKLIST="acme.com, mega.lo.mania"

Stop Forum SPAM API

Another SPAM mitigation feature has been added. It is now possible to check form submission emails against the stopforumspam.org API. Enabling this feature will make reformulate slower because it has to make a network request to the API. It is also possible that network issues, or problems with the API itself result in failures. Any failure communicating with the API, or obtaining results from the API will result in the check being skipped. Only positive matches against the data will be considered valid SPAM.

This feature is enabled by setting the FORMULATE_SPAM_BLOCKING environment variable to true.

Deployment

A Dockerfile is included in the source repository to aid in containerized deployments.

Dependencies

~27–43MB
~778K SLoC