diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..2841035 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,43 @@ +name: Docker Build and Push + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + env: + DOCKER_CLI_AGGREGATE: 1 + DOCKER_BUILDKIT: 1 + + strategy: + matrix: + base_image_tag: + - ubuntu-20.04 + - ubuntu-22.04 + + steps: + - name: Checkout code + + uses: actions/checkout@v4 + - name: Set up Docker Buildx + + uses: docker/setup-buildx-action@v1 + - name: Login to Docker Hub + uses: docker/login-action@v1 + + with: + username: ${{ vars.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + - name: Build and push Docker image + run: | + docker buildx create --use + docker buildx build \ + -t ${{ vars.DOCKER_HUB_USERNAME }}/srnjak-dev-playground-mail:latest \ + -t ${{ vars.DOCKER_HUB_USERNAME }}/srnjak-dev-playground-mail:${{ matrix.base_image_tag }} \ + -t ${{ vars.DOCKER_HUB_USERNAME }}/srnjak-dev-playground-mail:${{ matrix.base_image_tag }}-${{ github.run_number }} \ + --build-arg BASE_IMAGE_TAG=${{ matrix.base_image_tag }} \ + --push . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3968cc4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Use the specified Ubuntu version as a build argument +ARG BASE_IMAGE_TAG=latest + +# Use the base srnjak-dev-playground image with the specified tag +FROM srnjak/srnjak-dev-playground:${BASE_IMAGE_TAG} +MAINTAINER Grega Krajnc, srnjak.com + +# Set environment variables +ENV RELAY_HOST="[mail.example.com]:465" +ENV USERNAME="" +ENV PASSWORD="" + +# Install necessary packages +RUN apt-get update \ + && apt-get install -y postfix \ + && apt-get install -y mailutils \ + && rm -rf /var/lib/apt/lists/* + +# Configure Postfix +COPY postfix/main.cf /etc/postfix/main.cf + +# Create an entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Start Postfix using the entrypoint script +ENTRYPOINT /entrypoint.sh \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dce429d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Grega Krajnc + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7570839 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# srnjak-dev-playground-mail Docker Image + +This Docker image is an extension of the `srnjak-dev-playground` image, providing additional support for sending emails from the bash console using Postfix and Mailutils. + +## Usage + +### Building the Image + +```bash +docker build -t srnjak-dev-playground-mail . +``` + +### Running a Container + +To run the container, you can use either the `--env-file` option or the `-e` flag to specify environment variables directly. +Below are examples for both methods: + +#### Using `--env-file`: + +```bash +docker run --env-file env.list -it srnjak-dev-playground-mail +``` + +Ensure that you have an `env.list` file containing the necessary environment variables for email configuration, including `RELAY_HOST`, `USERNAME`, and `PASSWORD`. Here is an example `env.list` file: + +```plaintext +RELAY_HOST="[mail.example.com]:465" +USERNAME="your_username" +PASSWORD="your_password" +``` + +#### Using `-e`: + +```bash +docker run -e RELAY_HOST="[mail.example.com]:465" -e USERNAME="your_username" -e PASSWORD="your_password" -it srnjak-dev-playground-mail +``` + +Replace the values in quotes with your specific configuration details. + +### Sending a Test Email + +Once the container is running, you can send a test email using the following command: + +```bash +echo "Test message" | mail -s "Test" -a "From: sender@example.com" recipient@example.com +``` + +Replace `recipient@example.com` with the desired recipient's email address, and update the `"From: sender@example.com"` to specify the desired sender's email address. + +## Dependencies + +- Based on the `srnjak-dev-playground` image +- Postfix +- Mailutils + +## Docker Hub +The Docker image is available on Docker Hub: +- [srnjak/srnjak-dev-playground-mail](https://hub.docker.com/r/srnjak/srnjak-dev-playground-mail) + +## License + +This Docker image is licensed under the [MIT License](LICENSE). diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..a4c57fe --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Update main.cf with the environment variable values +sed -i "s|RELAY_HOST|${RELAY_HOST}|" /etc/postfix/main.cf + +# Create sasl_passwd file +echo "$RELAY_HOST $USERNAME:$PASSWORD" > /etc/postfix/sasl_passwd +chmod 600 /etc/postfix/sasl_passwd +postmap /etc/postfix/sasl_passwd + +# Start Postfix +service postfix start + +# Start bash shell +exec /bin/bash diff --git a/postfix/main.cf b/postfix/main.cf new file mode 100644 index 0000000..cd78b15 --- /dev/null +++ b/postfix/main.cf @@ -0,0 +1,8 @@ +smtp_sasl_auth_enable = yes +smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd +smtp_sasl_security_options = noanonymous +smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt +smtp_tls_wrappermode = yes +smtp_tls_security_level = encrypt +relayhost = RELAY_HOST +maillog_file = /var/log/mail.log