[My project work using Python and Flask]
Build an anti-spam, double opt-in Email form with Python
For the mitigation of email spam, bots and form submission attacks, we use a double opt-in email form.
A single opt-in form just allows anybody including bots to enter an email address and submit it on your website. Without additional protection like "captcha" or cloudflare, your web app will receive invalid submissions that will waste your system resources. If you're running a cronjob to send out periodic emails, your server will attempt to message the invalid email addresses resulting in errors.
We can include a double opt-in form which requires the submitter to confirm their email address upon receipt to their mailbox. This can be in addition to a more technical approach using cloudflare or "captca".
-Common Python modules for web forms including using templates, a redirect and notification flash
from flask import Flask, render_template, request, url_for, redirect, flash
-For mailing messages
from flask_mail import Mail, Message
-To include a timestamp when saving to a database
from datetime import datetime
- For using a SQL database
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import func
- For santizing requests
import secrets
import bleach
import requests