mftp.py continuously monitors the CDC Noticeboard and forwards incoming notices to the configured email address, whether it's an individual account or a Google Group.
Table of Contents
To set up a local instance of the application using docker, follow the steps below.
The following requirements are to be satisfied for the project to function properly:
- docker
- This project depends on ERP Login module by Arpit Bhardwaj for the ERP Login workflow. Read its documentation and setup your OTP fetching token mentioned in second point (
OTP_CHECK_INTERVAL
) of optional arguments.
-
Get the docker image
You can get the docker image from either docker-hub or by buiilding it locally:
- Pull from docker-hub
sudo docker pull metakgporg/mftp
- Build from Dockerfile
- Clone the repository and cd into it
git clone https://github.com/metakgp/mftp cd mftp/mftp
- Build the image
sudo docker build -t metakgporg/mftp .
- Clone the repository and cd into it
- Pull from docker-hub
-
Create a directory which will contain your tokens and env.py, name it as
mftp_config
-
Follow the steps to configure mail sending. Skip this step if you wish to use method not involving mails, for example, ntfy
-
Follow the steps to configure env variables
It is mandatory to provide both of the following env variables
before the docker-compose command.
MFTP_CONFIG
: Absolute path tomftp_config
directoryMFTP_MODE
: Mode of sending mail - --smtp, --gmail-api and --ntfy
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE=--smtp docker-compose up -d # Using SMTP for sending mails
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE=--gmail-api docker-compose up -d # Using Gmail API for sending mails
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE=--ntfy docker-compose up -d # Using Gmail API for sending mails
It is mandatory to provide either of the following flags to the execution command.
-
--smtp
: Using SMTP for sending mailssudo docker run -d \ -v /path/to/mftp_config/env.py:/mftp/env.py \ -v /path/to/mftp_config/token.json:/mftp/token.json \ -v /path/to/mftp_config/credentials.json:/mftp/credentials.json \ -v /path/to/mftp_config/mail_send_token.json:/mftp/mail_send_token.json \ -v /path/to/mftp_config/mail_send_creds.json:/mftp/mail_send_creds.json \ -v /path/to/mftp_config/.lsnif:/mftp/.lsnif \ -v /path/to/mftp_config/.ntfy.lsnsf:/mftp/.ntfy.lsnsf \ -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ metakgporg/mftp --smtp
-
--gmail-api
: Using Gmail API for sending mailssudo docker run -d \ -v /path/to/mftp_config/env.py:/mftp/env.py \ -v /path/to/mftp_config/token.json:/mftp/token.json \ -v /path/to/mftp_config/credentials.json:/mftp/credentials.json \ -v /path/to/mftp_config/mail_send_token.json:/mftp/mail_send_token.json \ -v /path/to/mftp_config/mail_send_creds.json:/mftp/mail_send_creds.json \ -v /path/to/mftp_config/.lsnif:/mftp/.lsnif \ -v /path/to/mftp_config/.ntfy.lsnsf:/mftp/.ntfy.lsnsf \ -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ metakgporg/mftp --gmail-api
-
--ntfy
: Using NTFY to serve notificationsudo docker run -d \ -v /path/to/mftp_config/env.py:/mftp/env.py \ -v /path/to/mftp_config/token.json:/mftp/token.json \ -v /path/to/mftp_config/credentials.json:/mftp/credentials.json \ -v /path/to/mftp_config/mail_send_token.json:/mftp/mail_send_token.json \ -v /path/to/mftp_config/mail_send_creds.json:/mftp/mail_send_creds.json \ -v /path/to/mftp_config/.lsnif:/mftp/.lsnif \ -v /path/to/mftp_config/.ntfy.lsnsf:/mftp/.ntfy.lsnsf \ -v /path/to/mftp_config/.session:/mftp/.session \ --restart=unless-stopped \ --name mftp \ metakgporg/mftp --ntfy
It is also possible to run these docker containers as a cronjob:
-
- Comment out the line
restart: unless-stopped
- Append
--cron
into theMFTP_MODE
env variable. For example:- Using Cronjob to run container and SMTP to send mails
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE="--smtp --cron" docker-compose up -d
- Using Cronjob to run container and Gmail API to send mails
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE="--gmail-api --cron" docker-compose up -d
- Using Cronjob to run container and ntfy to send mails
sudo MFTP_CONFIG=/path/to/mftp_config MFTP_MODE="--ntfy --cron" docker-compose up -d
- Using Cronjob to run container and SMTP to send mails
- Comment out the line
-
- Remove
--restart=unless-stopped
flag & append--cron
at the end of any of these commands. For example:sudo docker run -d \ -v /path/to/mftp_config/env.py:/mftp/env.py \ -v /path/to/mftp_config/token.json:/mftp/token.json \ -v /path/to/mftp_config/credentials.json:/mftp/credentials.json \ -v /path/to/mftp_config/mail_send_token.json:/mftp/mail_send_token.json \ -v /path/to/mftp_config/mail_send_creds.json:/mftp/mail_send_creds.json \ -v /path/to/mftp_config/.lsnif:/mftp/.lsnif \ -v /path/to/mftp_config/.ntfy.lsnsf:/mftp/.ntfy.lsnsf \ -v /path/to/mftp_config/.session:/mftp/.session \ --name mftp \ metakgporg/mftp --gmail-api --cron
- Remove
- Add the updated command with desired cron expression into your cronjob using crontab -e
To set up a local instance of the application without using docker, follow the steps below.
The following requirements are to be satisfied for the project to function properly:
- python3
>=python3.10
sudo apt update sudo apt install python3
- This project depends on ERP Login module by Arpit Bhardwaj for the ERP Login workflow. Read its documentation and setup your OTP fetching token mentioned in second point (
OTP_CHECK_INTERVAL
) of optional arguments.
Now that the environment has been set up and configured to properly compile and run the project, the next step is to download and configure the project locally on your system.
- Clone the repository
git clone https://github.com/metakgp/mftp cd mftp/mftp
- Install required dependencies
pip3 install -r requirements.txt
Note
Since, port 465
(SMTP with SSL) on campus LAN is blocked and if you want to host mftp on an internal server on the campus LAN, it will need another method then SMTP.
However, it is preferred to use SMTP when hosting on external server as SMTP is the convenient of the two.
The tool provides two methods of sending emails.
-
--smtp
- Create an app password for the senders' email.
- After creating app password use it as your
FROM_EMAIL_PASS
value in next step.
-
--gmail-api
- Follow this quick start guide to configure gmail api on the senders' mail.
- After successfull configuration of gmail api, you can leave the value of
FROM_EMAIL_PASS
as it is in the next step. - Save the generated token as
mail_send_token.json
-
- Copy
env.example.py
asenv.py
. It looks like this:# ERP Credentials (MUST) ROLL_NUMBER = "XXYYXXXXX" # Institute Roll Number PASSWORD = "**********" # ERP Password SECURITY_QUESTIONS_ANSWERS = { # ERP Secret Questions and their Answers "Q1" : "A1", "Q2" : "A2", "Q3" : "A3", } # EMAIL (via SMTP) ## Senders' Credentials FROM_EMAIL = "abc@gmail.com" # Notification Sender Email-id FROM_EMAIL_PASS = "**********" # App password for the above email-id ## EMAIL - Receiver's Address BCC_EMAIL_S = ["xyz@googlegroups.com", "abc@googlegroups.com"] # Multiple mails for bcc # BCC_EMAIL_S = ["xyz@googlegroups.com"] # This is how you can set single mail in a list # NTFY NTFY_BASE_URL = "https://ntfy.sh" NTFY_TOPIC = "mftp" ## Optional: only if you want a custom icon NTFY_TOPIC_ICON = "https://miro.medium.com/v2/resize:fit:600/1*O94LHxqfD_JGogOKyuBFgA.jpeg" ## Optional: only if the topic is restricted NTFY_USER = "testuser" NTFY_PASS = "fakepassword"
- Update the values inside the
double quotes
("). DO NOT CHANGE VAR NAMES.
- Copy
It is mandatory to provide either of the following flags to the execution command:
-
--smtp
: Using SMTP for sending mailspython3 mftp.py --smtp
-
--gmail-api
: Using GMAIL API for sending mailspython3 mftp.py --gmail-api
-
--ntfy
: Using NTFY for serving notificationspython3 mftp.py --ntfy
It is also possible to bypass the continuous loop - which executes the code after every 2 minutes - using the --cron
argument:
python3 mftp.py --smtp --cron
python3 mftp.py --gmail-api --cron
python3 mftp.py --ntfy --cron