From 306dec1d455cee135e78eb5c483e0833ed9a150d Mon Sep 17 00:00:00 2001 From: vista Date: Sat, 18 Mar 2023 01:35:50 +0100 Subject: [PATCH] dev (#1) Reviewed-on: https://git.narvas.tech/vista/msmtp/pulls/1 --- build/start-container.sh | 57 ++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/build/start-container.sh b/build/start-container.sh index 81c6271..3877c2c 100644 --- a/build/start-container.sh +++ b/build/start-container.sh @@ -1,15 +1,50 @@ #! /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 -echo -e "Subject: ${SUBJECT}\n\n${MESSAGE}" | msmtp ${TO_ADDRESS} \ No newline at end of file +if [ -n "${SMTP_FROM_FILE}" ]; then + SMTP_FROM=$(cat ${SMTP_FROM_FILE}); +fi + +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 + +IFS= + +if [ -n "${EMAIL_FILE}" ]; then + EMAIL=$(cat ${EMAIL_FILE}); +else + if [ -z "${EMAIL}" ]; then + EMAIL="To: ${TO_ADDRESSES}\nSubject: ${SUBJECT}\n\n${MESSAGE}"; + fi +fi + +if [ -z "${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