A Flask app running a POST
API to handle subscribing to a Mailman
3 list from a static website. Designed to
attach to an existing
docker-mailman
network, this app
will take requests to subscribe or unsubscribe users via the Python
mailmanclient
.
listEmail
- The email address you would like to subscribe to the listlistName
- The name of the person you would like to subscribe to the listlist-name
- Wherename
is an arbitrary string.value
oflist-foo
should be the Mailman list name likelist@list.com
. Accepts multiplelist-name
fields in the form so you can optionally subscribe someone to multiple lists at one timesuccess_redirect_url
- The URL you'd like the API to redirect to if the subscription was successfulerror_redirect_url
- The URL you'd like the API to redirect to if the subscription was unsuccessfulemail
- Honeypot field (see below for more details). This field should be hidden and is intended to prevent spam
<form action="https://fmmss.example.com/1.0/subscribe" method="post">
<label for="listEmail">Email address:</label><br>
<input type="text" name="listEmail" value=""><br>
<label for="listName">Name:</label><br>
<input type="text" name="name" value=""><br><br>
<input type="hidden" name="list-writers" value="name@example.com" />
<input type="hidden" name="success_redirect_url" value="https://example.com/subscribe-success.html">
<input type="hidden" name="error_redirect_url" value="https://example.com/subscribe-error.html">
<input class="ohnohoney" type="text" name="email" tabindex="-1" autocomplete="off">
<input type="submit" value="Join the List">
</form>
See below for more details on the ohnohoney
class.
email
- The address you'd like to unsubscribelist
- The list you'd like to unsubscribe the person fromsuccess_redirect_url
- The URL you'd like the API to redirect to if the unsubscription was successfulerror_redirect_url
- The URL you'd like the API to redirect to if the unsubscription was unsuccessful
To prevent bots from submitting spam subscriptions, I use a honeypot on the
subscription form. This isn't a required field but if you find yourselves with
swarming bees, the honey pot might help. The name="email"
input attribute is
guaranteed to trap the bot into filling out the field. The ohnohoney
class
visually hides the field though. So if the POST
request contains information
in the email
field, we can assume it's spam. To hide the honey pot field, add
the class ohnohoney
and include the following CSS somewhere in your
stylesheet:
.ohnohoney{
opacity: 0;
position: absolute;
top: 0;
left: 0;
height: 0;
width: 0;
z-index: -1;
}