Server - Contents

Flask - Mail

Prerequisites: a. Basic Server (Debian 10.3 64bit) with Webmin, FTP, Firewall, iRedmail and Basic 3-page Flask Website functioning
Lastly, that one has created an email address such as 'info@example.com'

Via iRedadmin (eg. https://example.com/iredadmin), create a user's mailbox 'info' in one's own domain (eg. info@example.com).

Part A: Flask WTF and Flask Mail

From the first Flask website, there is the contactus page but without a form to create and send mail messages. To embed and activate such a form, one needs to install Flask WTF and Flask Mail on both the PC and server python environments.

On the PC, via 'PowerShell'[Win10] or in Win 7+, typing in 'cmd' to get the console:

python -m pip install flask-wtf flask-mail email_validator

Download the Enhanced 3-page Flask Website here and unzip the contents of this file to the PC's 'myapp' directory:

cd Documents\Scripts\myapp
ipython myproject.py // run the application

Modify myproject.py to change 'example.com' with your domain.

To test the new configuration, enter in the PC's browser, http://localhost:5000, the earlier three page Flask website should appear but with a contact form in 'Contact Us'.
Note: No email can be sent from the PC (no mailserver installed).

Part B: Modified myproject.py

Prepare the server for Flask Mail

Via a FTP client (eg. Filezilla), transfer a of copy the modified myproject.py file of the PC's 'myapp' folder into corresponding server 'myapp' directory together with the other directories [templates, static] replacing the existing ones on the server.

sammy@imega:$ cd ~/myapp
sammy@imega:~/myapp$ . venv/bin/activate // if venv is not activate, then activate
sammy@imega:~/myapp$ pip install flask-wtf flask-mail email_validator
(myvenv) sammy@imega:~/myapp$ ipython myproject.py

With the browser: Enter one's domain at port:5000 (eg. http://example.com:5000), the same three page Flask website should appear with a functional mailform in 'contactus'. Test the mailform. If successful, use the key-combo 'ctl'+c to exit.

Notes:
a. Restart the Nginx Webserver and the WSGI service whenever changes are made. This can also be done via Webmin-> Others -> CommandShell (drop 'sudo').
sammy@imega:/myapp$ sudo systemctl restart myproject
sammy@imega:/myapp$ sudo systemctl restart nginx
b. For mail not to end up in a spambox must have the DNS correctly set. These are settings as expressed in iRedMail-Extras as well as those DNS/MTA+STS setting as expresed in iRedMail-Switch - Part:D.
c. In the myproject.py on the server, turn off debugging by changing its last line to:app.run()
Flask
Server - Contents