A small python based server which allows you to send mails from a static webpage via a simple HTML form.
Amongst others, mailstatic is based on technologies like
How does it work?
Simple and straight forward:
- The POST request of your form is forwarded to your mailstatic server.
- The server accepts the post request and its parameters and sends a mail with the given information towards the provided address.
- The provided email address receives the mail that was created by the HTML form.
Use Cases & Advantages
Additionally to a much thinner project, mailstatic brings a separate system taking care of all the user input processing which can be scaled to any need. The server saves all of the received input in a PostgreSQL DB which allows you to track, retrace and process the received input.
Due to security mechanisms like Googles Recaptcha v2 an abuse of the service is prevented.
To prevent abuse there is also a configurable rate limit set for every endpoint which is capable of sending emails.
There are two ways to run the server. But in any case you should make sure the server is configured correctly.
web-example.env provides necessary environment variables that the server uses to process certain actions:
RECAPTCHA_SITEKEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI RECAPTCHA_SECRET=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe IMAP_SERVER=mail.test.server IMAP_USERfirstname.lastname@example.org IMAP_PASSWORD=XXXXXXXXXXXXX SERVER_ADDRESS=https://mailstatic.net DATABASE_URI=postgresql+psycopg2://postgres:postgres@db/postgres
You need to provide details for your IMAP Server and it's user so that the server can use a provided email account to forward the content of the POST request received from the HTML form. Additionally you can configure your server address, the URI of the database and your Google Recaptcha information (check out the Googles Recaptcha Site to receive your information).
After providing the necessary information you can start the server.
Using python on your machine
- Open your commandline and navigate inside the project folder.
pip install -r .\requirements.txtto install necessary dependencies (in case it's not working try
python -m pip install -r .\requirements.txtpip install -r .\requirements.txt).
python .\runserver.pyto boot the server.
- You should see the following message
Running on http://[::]:5000/ (Press CTRL+C to quit).
- If you want to start the production server, start it with gunicorn:
pipenv run pipenv run gunicorn mailstatic:app --bind 0.0.0.0:5000. It may be a good idea to use a reverse-proxy like nginx in front of it to terminate SSL and buffer slow requests. Checkout the project for configuration examples.
- Open your command-line and navigate inside the project folder.
- Check if the provided
docker-compose.ymlfile serves your needs. (E.g. the run command)
docker-compose -f docker-compose.prod.yml upto start the container.
- You should see the following message:
Running on http://[::]:5000/ (Press CTRL+C to quit)
Alternatively you can also pull our image directly from the docker hub using
docker pull taliox/mailstatic.
To setup a HTML form on your webpage simply copy the following code:
<form action="email@example.com" method="POST"> <input name="name" required="" type="text"> <input name="replyto" required="" type="email"> <textarea name="message"></textarea> <input value="Send" type="submit"> </form>
All input of this form is now forwarded to your server.
Pull requests for improvements of the project or its documentation are also highly appreciated.
This library and its content is released under the MIT License.