From bb96283ad52f1993290a65fb237c88349a2c0676 Mon Sep 17 00:00:00 2001 From: vista Date: Fri, 17 Mar 2023 22:38:14 +0100 Subject: [PATCH 1/4] Update 'build/start-container.sh' --- build/start-container.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/start-container.sh b/build/start-container.sh index 81c6271..4b16d0f 100644 --- a/build/start-container.sh +++ b/build/start-container.sh @@ -12,4 +12,6 @@ from ${SMTP_FROM} user ${SMTP_USER} password ${SMTP_PASSWORD}" > ~/.msmtprc +chmod 600 ~/.msmtprc + echo -e "Subject: ${SUBJECT}\n\n${MESSAGE}" | msmtp ${TO_ADDRESS} \ No newline at end of file From 0e47e74ac5d3fcb0bc307335b414f2432db3a410 Mon Sep 17 00:00:00 2001 From: vista Date: Fri, 17 Mar 2023 23:19:41 +0100 Subject: [PATCH 2/4] feat: add option to read variables from file --- build/start-container.sh | 55 +++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/build/start-container.sh b/build/start-container.sh index 4b16d0f..88d038f 100644 --- a/build/start-container.sh +++ b/build/start-container.sh @@ -1,17 +1,48 @@ #! /usr/bin/env sh -echo "defaults -auth on -tls on +if [ -n "${SMTP_HOST_FILE}" ]; then + SMTP_HOST=$cat ${SMTP_HOST_FILE}); +fi -account default -host ${SMTP_HOST} -port ${SMTP_PORT} -tls_starttls ${SMTP_STARTTLS} -from ${SMTP_FROM} -user ${SMTP_USER} -password ${SMTP_PASSWORD}" > ~/.msmtprc +if [ -n "${SMTP_PORT_FILE}" ]; then + SMTP_PORT=$(cat ${SMTP_PORT_FILE}); +fi -chmod 600 ~/.msmtprc +if [ -n "${SMTP_FROM_FILE}" ]; then + SMTP_FROM=$(cat ${SMTP_FROM_FILE}); +fi -echo -e "Subject: ${SUBJECT}\n\n${MESSAGE}" | msmtp ${TO_ADDRESS} \ No newline at end of file +if [ -n "${SMTP_USER_FILE}" ]; then + SMTP_USER=$(cat ${SMTP_USER_FILE}); +fi + +if [ -n "${SMTP_PASSWORD_FILE}" ]; then + SMTP_PASSWORD=$(cat ${SMTP_PASSWORD_FILE}); +fi + +if [ -n "${EMAIL_FILE}" ]; then + EMAIL=$(cat ${EMAIL_FILE}); +else + if [ -n "${EMAIL}" ]; then + EMAIL="To: ${TO_ADDRESS}\nSubject: ${SUBJECT}\n\n${MESSAGE}"; + fi +fi + +if [ -n "${MSMTP_CONFIG_FILE}" ]; then + MSMTP_CONFIG_FILE="~/.msmtprc" + touch ${MSMTP_CONFIG_FILE} + chmod 600 ${MSMTP_CONFIG_FILE} + echo "defaults + auth ${SMTP_AUTH:-on} + tls ${SMTP_TLS:-on} + + account default + host ${SMTP_HOST} + port ${SMTP_PORT:-587} + tls_starttls ${SMTP_STARTTLS:-on} + from ${SMTP_FROM} + user ${SMTP_USER} + password ${SMTP_PASSWORD}" > ${MSMTP_CONFIG_FILE} +fi + +echo -e "${EMAIL}" | msmtp --read-recipients -C ${MSMTP_CONFIG_FILE} \ No newline at end of file From 2f61a64ef02fbfbdaa18236c17a7c3651741b288 Mon Sep 17 00:00:00 2001 From: vista Date: Sat, 18 Mar 2023 00:14:34 +0100 Subject: [PATCH 3/4] Update 'build/start-container.sh' --- build/start-container.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build/start-container.sh b/build/start-container.sh index 88d038f..3877c2c 100644 --- a/build/start-container.sh +++ b/build/start-container.sh @@ -20,16 +20,18 @@ if [ -n "${SMTP_PASSWORD_FILE}" ]; then SMTP_PASSWORD=$(cat ${SMTP_PASSWORD_FILE}); fi +IFS= + if [ -n "${EMAIL_FILE}" ]; then EMAIL=$(cat ${EMAIL_FILE}); else - if [ -n "${EMAIL}" ]; then - EMAIL="To: ${TO_ADDRESS}\nSubject: ${SUBJECT}\n\n${MESSAGE}"; + if [ -z "${EMAIL}" ]; then + EMAIL="To: ${TO_ADDRESSES}\nSubject: ${SUBJECT}\n\n${MESSAGE}"; fi fi -if [ -n "${MSMTP_CONFIG_FILE}" ]; then - MSMTP_CONFIG_FILE="~/.msmtprc" +if [ -z "${MSMTP_CONFIG_FILE}" ]; then + MSMTP_CONFIG_FILE=~/.msmtprc touch ${MSMTP_CONFIG_FILE} chmod 600 ${MSMTP_CONFIG_FILE} echo "defaults From 4d531c2af92ef841263fcc5f159928c7a9ae351f Mon Sep 17 00:00:00 2001 From: vista Date: Sat, 18 Mar 2023 15:02:27 +0100 Subject: [PATCH 4/4] fix: missing ( --- build/start-container.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/start-container.sh b/build/start-container.sh index 3877c2c..a1aecc9 100644 --- a/build/start-container.sh +++ b/build/start-container.sh @@ -1,7 +1,7 @@ #! /usr/bin/env sh if [ -n "${SMTP_HOST_FILE}" ]; then - SMTP_HOST=$cat ${SMTP_HOST_FILE}); + SMTP_HOST=$(cat ${SMTP_HOST_FILE}); fi if [ -n "${SMTP_PORT_FILE}" ]; then