Code Monkey home page Code Monkey logo

docker-mail's Introduction

logo

Automated mail notifications

Build client Build server

This project has been developed based on the need to notify users when their Nomad jobs are assigned after a delay time (currently set to 7 days). For this and due to specific needs of the mail service used it's necessary to take a client-server approach.

The idea is that the client part will be deployed as a side task (mailtask) in a Nomad job, taking care of all the temporal logic. If the premise is met then it will make a request to the server, which will be in charge of sending the email.

Both Docker images are available in the project's Harbor registry:

  • registry.services.ai4os.eu/ai4os/docker-mail:client
  • registry.services.ai4os.eu/ai4os/docker-mail:server

Usage

As mentioned, the idea is to send an email notification if the Nomad Job has been scheduled after the specified deadline.

This means that if the Job is executed within the first 7 days (default) of its creation, no email will be sent. Otherwise, this task will notify the job author when its execution begins.

For this purpose, the client-side script reads a set of environment variables from the container, which must be specified in the Nomad Job.

  • NUM_DAYS: Number of days from which the notification will be sent by email (It has a default value of 7 days).

  • DATE: Date the nomad job was created.

  • DEST: Email address to notify the start of the Job execution.

  • BODY: Body of the mail.

  • SUBJECT: Subject of the mail.

  • MAILING_TOKEN: Must be the same on the client and server side.

The server side only needs the MAILING_TOKEN environment variable to work.

API

The server implements an API developed in python through FastApi. This API listens on port 8082. Once the service is up, the API specification can be accessed in /docs.

The status of the service can be checked through a GET request to the root route /. If the service is active, it should respond with the following message:

{"message": "Server is UP"}

Emails can be sent through a GET request to /notify with the following query params:

  • email: Email recipient.

  • body: Body of the mail.

  • subject: Subject of the mail.

  • token: Security token. Must be the same on the client and server side.

If the request is received correctly and the token is correct, the following message is returned

{"status": "ok", "message": "Notification sent successfully"}

Otherwise, if an incorrect token is sent, the following message is returned

{"status": "error", "message": "Invalid token, notification not sent"}

Exim4

Server is configured to send emails via exim4. The Docker image already has exim4 installed, but it needs to read the configuration files from the host machine, located in /etc/exim4.

For this purpose, it is necessary to mount the host configuration folder on the guest file system.

docker run ... -v /etc/exim4:/etc/exim4 ...

Note: The docker image already restarts the exim4 service after boot so it can use the new configuration files.

Important: If Docker was installed via Snap, it will not copy files from privileged directories when mounting, according to this issue.

At the moment, it is possible to copy the host configuration files to a non-privileged path.

Demo

Both the client and the server can be easily deployed locally using the scripts in the scripts folder.

To allow connectivity between containers, it is necessary to previously execute the following command:

docker network create --subnet=192.168.1.0/24 mailing_net

Containers can then be deployed by running launch_client.sh and launch_server.sh. Environment variables for each instance are specified through the vars.env file in the server and client folders. For example:

  • For the client container
  NUM_DAYS=7
  DATE="2024-01-07T11:19:29.914177+01:00"
  [email protected]
  BODY="Body of the test mail"
  SUBJECT="Test mail"
  MAILING_TOKEN=1234
  • For the server container
  MAILING_TOKEN=1234

Depending on the Date variable, the email will be sent or not.

docker-mail's People

Contributors

sftobias avatar ignacioheredia avatar

Watchers

Alvaro Lopez Garcia avatar Viet Tran avatar Valentin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.