2015-04-19 22:30:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-09 07:06:30 +00:00
|
|
|
[ "${DEBUG}" == "yes" ] && set -x
|
|
|
|
|
|
|
|
function add_config_value() {
|
|
|
|
local key=${1}
|
|
|
|
local value=${2}
|
|
|
|
local config_file=${3:-/etc/postfix/main.cf}
|
|
|
|
[ "${key}" == "" ] && echo "ERROR: No key set !!" && exit 1
|
|
|
|
[ "${value}" == "" ] && echo "ERROR: No value set !!" && exit 1
|
|
|
|
|
|
|
|
echo "Setting configuration option ${key} with value: ${value}"
|
2019-02-17 17:50:21 +00:00
|
|
|
postconf -e "${key} = ${value}"
|
2018-05-09 07:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 22:30:41 +00:00
|
|
|
[ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1
|
|
|
|
[ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1
|
|
|
|
[ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1
|
2018-03-06 06:18:30 +00:00
|
|
|
[ -z "${SERVER_HOSTNAME}" ] && echo "SERVER_HOSTNAME is not set" && exit 1
|
2015-04-19 22:30:41 +00:00
|
|
|
|
2018-05-24 03:14:45 +00:00
|
|
|
SMTP_PORT="${SMTP_PORT-587}"
|
|
|
|
|
2015-05-23 04:45:58 +00:00
|
|
|
#Get the domain from the server host name
|
2018-05-09 07:06:30 +00:00
|
|
|
DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'`
|
2015-05-23 04:45:58 +00:00
|
|
|
|
2018-05-09 07:06:30 +00:00
|
|
|
# Set needed config options
|
|
|
|
add_config_value "myhostname" ${SERVER_HOSTNAME}
|
|
|
|
add_config_value "mydomain" ${DOMAIN}
|
|
|
|
add_config_value "mydestination" '$myhostname'
|
|
|
|
add_config_value "myorigin" '$mydomain'
|
2018-05-24 03:14:45 +00:00
|
|
|
add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}"
|
2018-05-09 07:06:30 +00:00
|
|
|
add_config_value "smtp_use_tls" "yes"
|
|
|
|
add_config_value "smtp_sasl_auth_enable" "yes"
|
|
|
|
add_config_value "smtp_sasl_password_maps" "hash:\/etc\/postfix\/sasl_passwd"
|
|
|
|
add_config_value "smtp_sasl_security_options" "noanonymous"
|
2015-05-13 06:06:38 +00:00
|
|
|
|
2018-05-09 07:06:30 +00:00
|
|
|
# Create sasl_passwd file with auth credentials
|
|
|
|
if [ ! -f /etc/postfix/sasl_passwd ]; then
|
|
|
|
grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1
|
|
|
|
if [ $? -gt 0 ]; then
|
|
|
|
echo "Adding SASL authentication configuration"
|
2018-05-24 03:14:45 +00:00
|
|
|
echo "[${SMTP_SERVER}]:${SMTP_PORT} ${SMTP_USERNAME}:${SMTP_PASSWORD}" >> /etc/postfix/sasl_passwd
|
2018-05-09 07:06:30 +00:00
|
|
|
postmap /etc/postfix/sasl_passwd
|
|
|
|
fi
|
|
|
|
fi
|
2015-04-19 22:30:41 +00:00
|
|
|
|
2019-01-26 22:12:50 +00:00
|
|
|
#Set header tag
|
2019-01-27 01:50:34 +00:00
|
|
|
if [ ! -z "${SMTP_HEADER_TAG}" ]; then
|
2019-01-20 04:58:15 +00:00
|
|
|
postconf -e "header_checks = regexp:/etc/postfix/header_tag"
|
|
|
|
echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" > /etc/postfix/header_tag
|
2019-01-26 22:12:50 +00:00
|
|
|
echo "Setting configuration option SMTP_HEADER_TAG with value: ${SMTP_HEADER_TAG}"
|
2019-01-16 17:34:48 +00:00
|
|
|
fi
|
|
|
|
|
2018-05-09 07:06:30 +00:00
|
|
|
#Start services
|
|
|
|
supervisord
|