Mailservice is an application developed in python using Django, able to send mail to any user and has support to cc and bcc along with subject and body. It also has support to parse CSV file which is list of email addresses, to whom the mail will be sent. I've used ELK stack for the log management, which also indexes the emails stored in DB along with the web requests. There is a periodic task running every 30 minutes, which curates the emails sent in that time period and sends the CSV export to the admins.
- Python 3.6.7
- Django 2.0.7
- elasticsearch 6.6.0
- logstash 6.6.0
- kibana 6.6.0
- crontab 2.3.6
- celery 4.2.1
- redis 3.2.0
sudo apt updatesudo apt install python3.6
pip is a package management system for python.
sudo apt install python3-pip -ypip install Django==2.0.7
Virtualenv is a python environment builder. It is used to create isolated python environments.
pip install virtualenv
Create virtual environment for your project directory followed by commands
virtualenv -p python3 .pip freeze
start by source bin/activate
ends with deactivate
Run migrations
python manage.py migrate
Run your application in browser run the below command in your terminal and visit localhost:8000
python manage.py runserver
Elasticsearch requires Java SDK 8 to be installed
add-apt-repository ppa:webupd8team/javaapt install -y oracle-java8-set-default
Elasticsearch is used to index data from database for quick search.
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.debdpkg -i elasticsearch-6.3.2.debpip install django-elasticsearch-dsl
After installing open /etc/elasticsearch/elasticsearch.yml and edit and uncomment the line below
network.host: localhost
Now start and run the Elasticsearch service by following commands and visit localhost:9200
systemctl enable elasticsearch.servicesystemctl start elasticsearch.service
logstash is used to collect, process, and forward events and log messages
wget https://artifacts.elastic.co/downloads/logstash/logstash-6.6.0.debdpkg -i logstash-6.6.0.debpip install python3-logstash
After installing open /etc/logstash/logstash.yml and change the line below
http.host: "localhost"
Start and enable Logstash service
systemctl enable logstash.servicesystemctl start logstash.service
Kibana is used to visualize all the events, data and logs
wget https://artifacts.elastic.co/downloads/kibana/kibana-6.6.0.debdpkg -i kibana-6.6.0.deb
Next, open /etc/kibana/kibana.yml and update below two lines
server.host: "localhost"elasticsearch.url: "http://localhost:9200"
Start and enable Kibana service and visit localhost:5601 and configure an index pattern
systemctl enable kibana.servicesystemctl start kibana.service
After configure ELK with your project run below command for logstash and let it run continous
sudo /usr/share/logstash/bin/logstash -f /path/to/logstash.conf
Celery is a scheduler, that hits off tasks at regular periods. It has worker and beat services. Celery requires redis as a broker
pip install celery redis
Run worker and beat processes
celery -A mailservice worker -l info -Bcelery -A mailservice beat -l info -B
- Main landing page of the mailservice is localhost:8000.
- On compose-mail, you can send email to any user with support of cc and bcc.
- The fields
email to,cc, andbccsupports comma separated list of emails and has validation in place. - You can see records of emails in Email model.
- Check log records, to see all request logs, and emails indexed from DB. Remember, you will have to create index pattern before that.
- Run
celery -A mailservice worker -l info -Bwhich will send email report every 30 minutes to admins. - If no email found in last 30 minutes then it won't send report.