19.04.2018 by Jonatan Zint

A simple form sending service

How I didn't find simple form submitting software in the Internet

Recently I searched for a little piece of software to send emails from a webpage. Easy-peasy. I was totally certain that a quick search will bring up some easy-to-setup open source solution on the first page. That was not the case, instead I got offers from SaaS solutions like formspree.io, which of course is cool and all, but I was determined to have this little piece of software self-hosted. You know, decentralization, independence and all.

Since I couldn’t find a simple software to do that fairly little job for me I figured I’m gonna hack it myself with a bit of flask and share it for people with a similar issue.

So let me introduce you to formidable . A little flask application picking up a POST request from a web form sending it directly to a configured e-mail address:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import Flask, render_template, request, redirect
from flask_mail import Mail, Message
from os import environ

app = Flask(__name__)
app.config.from_object('config.default')
settings = environ.get('FORMIDABLE_SETTINGS_MODULE', None)
if settings:
    app.config.from_object(settings)

mail = Mail(app)


@app.route("/submit", methods=['POST'])
def submit():
    referrer = request.referrer
    next_page = request.form.get('next_page', app.config.get('THANKYOU_PAGE_DEFAULT'))
    originator = request.form.get('email', 'unknown')
    mailtext = render_template('new_submit_mail.txt', form=request.form, referrer=request.referrer)
    message = Message(body=mailtext,
                      subject='New form submission on {} from {}'.format(referrer, originator),
                      sender=app.config.get('MAIL_SENDER'),
                      recipients=app.config.get('MAIL_RECIPIENTS'),
                      reply_to=originator if originator != 'unknown' else None
                      )
    mail.send(message)

    return redirect(next_page)


if __name__ == '__main__':
    app.run()
Do you really need a SaaS for everything?

After putting this together in roughly 2 hours including setting this up with automatic deployment, nginx config, ssl and whatnot I felt kinda validated to not take a SaaS for this job. My first impulse was just to sign-up for a hassle-free solution like formspree.io to just wipe that task off my todo list, but spending a little time to have a provider independent solution where I can control privacy and uptime myself is worth it, as I think.