diff --git a/builds/send-report/Dockerfile b/builds/send-report/Dockerfile new file mode 100644 index 0000000..dc096b9 --- /dev/null +++ b/builds/send-report/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:latest + +RUN apk --no-cache add curl mutt + +COPY send.sh /usr/local/bin/send.sh +COPY init.sh /usr/local/bin/init.sh + +RUN chmod +x /usr/local/bin/send.sh /usr/local/bin/init.sh + +CMD ["/usr/local/bin/init.sh"] \ No newline at end of file diff --git a/builds/send-report/README.md b/builds/send-report/README.md new file mode 100644 index 0000000..808e17b --- /dev/null +++ b/builds/send-report/README.md @@ -0,0 +1,12 @@ +Environments to set: + +PDF_URL="https://example.tld/report.pdf" +TO_EMAIL="report@example.tld" +SMTP_SERVER="smtp.example.com" +SMTP_PORT="587" +SMTP_USER="your_username" +SMTP_PASSWORD="your_password" +FROM="Example " + +TMP_PDF="/tmp/report.pdf" +CRON_SCHEDULE="0 2 * * 0" diff --git a/builds/send-report/build.sh b/builds/send-report/build.sh new file mode 100644 index 0000000..a2118ac --- /dev/null +++ b/builds/send-report/build.sh @@ -0,0 +1,3 @@ +docker build . --tag registry.bhasher.com/send-report:latest + +docker push registry.bhasher.com/send-report:latest diff --git a/builds/send-report/init.sh b/builds/send-report/init.sh new file mode 100644 index 0000000..9da14b6 --- /dev/null +++ b/builds/send-report/init.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +CRON_SCHEDULE=${CRON_SCHEDULE:-"0 2 * * 0"} + +echo "$CRON_SCHEDULE /usr/local/bin/send.sh" > /etc/crontabs/root + +echo "Service ready on schedule $CRON_SCHEDULE" + +crond -f diff --git a/builds/send-report/send.sh b/builds/send-report/send.sh new file mode 100644 index 0000000..b934323 --- /dev/null +++ b/builds/send-report/send.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +TMP_PDF="/tmp/report.pdf" + +curl -o "$TMP_PDF" "$PDF_URL" + +if [ $? -eq 0 ]; then + echo "Sending the report as an attachment" | mutt -s "Weekly Report" -e "set smtp_url=smtps://${SMTP_USER}:${SMTP_PASSWORD}@${SMTP_SERVER}:${SMTP_PORT}" -e 'set from="${FROM}"' -a "$TMP_PDF" -- "${TO_EMAIL}" + + if [ $? -eq 0 ]; then + echo "Email sent successfully" + else + echo "Failed to send the email" + fi +else + echo "Failed to download the PDF" +fi + +rm -f "$TMP_PDF"