diff --git a/seqs/mailserver.sh b/seqs/mailserver.sh index 341cac8..384a96c 100755 --- a/seqs/mailserver.sh +++ b/seqs/mailserver.sh @@ -322,12 +322,16 @@ step_25() { echo " (chown $MAS_VIRTUAL_USER: .sendxmpprc; chmod 700 .sendxmpprc)" } -step_50_info() { echo "Adding relay host for sending mails"; } +step_50_info() { echo "Adding default relay host for sending mails"; } +step_50_alias() { ALIAS="default_relay"; } step_50() { - exe postconf -e "relayhost = $MAS_RELAYHOST" - exe postconf -e "smtp_sasl_auth_enable = yes" - exe postconf -e "smtp_sasl_password_maps = hash:$saslPassFile" - addConf -s "$MAS_RELAYHOST $MAS_RELAYUSER:$MAS_RELAYPASS" "$saslPassFile" + if [ ! -f "$saslPassFile" ] ; then + exe postconf -e "relayhost = $MAS_RELAYHOST" + exe postconf -e "smtp_sasl_auth_enable = yes" + exe postconf -e "smtp_sasl_password_maps = hash:$saslPassFile" + addConf -s "$MAS_RELAYHOST $MAS_RELAYUSER:$MAS_RELAYPASS" "$saslPassFile" + fi + echo " [I] Updating $saslPassFile" exe postmap "$saslPassFile" } saslPassFile="$mtaConfLoc/sasl_password" @@ -369,9 +373,61 @@ step_54() { } mtaRecipientAccessLoc="$mtaConfLoc/recipient_access" -step_100_info() { echo "Send testmail"; } +step_56_info() { echo "Add sender dependant relay with authentication"; } +step_56_alias() { ALIAS="sender_relay"; } +step_56() { + if [ ! -f "$mtaSenderRelayLoc" ] ; then + echo " [I] Generating $mtaSenderRelayLoc" + exep "echo \"# user@extern.com smtp:[mail.extern.com]:587\" > \"$mtaSenderRelayLoc\"" + exe postconf -e "smtp_sender_dependent_authentication = yes" + exe postconf -e "sender_dependent_relayhost_maps = hash:$mtaSenderRelayLoc" + exe postconf -e "smtp_sasl_security_options = noanonymous" + exe postconf -e "smtp_sasl_mechanism_filter = plain" + exe postconf -e "smtp_tls_security_level = encrypt" + exe postconf -e "smtp_tls_mandatory_ciphers = high" + echo " [I] Don't forget to add credentials for the new relay" + echo " [$saslPassFile]" + echo " user@extern.com username:passwort" + echo " postmap $saslPassFile" + fi + echo " [I] Updating $mtaSenderRelayLoc" + exe postmap "$mtaSenderRelayLoc" + exe postmap "$saslPassFile" +} +mtaSenderRelayLoc="$mtaConfLoc/sender_relay" + +step_100_info() { + echo "Send testmail [-u SYSTEMUSER | -f FROM] [TO]" + echoinfo "Send as current user to postmaster@\$MAS_DOMAIN by default" +} +step_100_alias() { ALIAS="test"; } step_100() { - echo -e "Subject: TestPostfix\nIt goes on" | sendmail martin@winklerfamilie.de + shift + local arg + local fromAdr + local toAdr="postmaster@$MAS_DOMAIN" + local asUser= + for arg in "$@" ; do + case "$1" in + -f) + shift + fromAdr="-f $1 " + shift + ;; + -u) + shift + asUser="sudo -u $1 " + shift + ;; + *) + break + ;; + esac + done + if [ ! -z $1 ] ; then + toAdr="$1" + fi + exe ${asUser}sh -c "echo \"Subject: Test from Postfix\nIt is \$(date)\n\nGreetings \$(whoami)\" | sendmail ${fromAdr}$toAdr" } step_102_info() { echo "Show mail queue"; }