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