diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index b6103e93..252986de 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -90,7 +90,6 @@ function register_functions() { if [ "$ENABLE_SASLAUTHD" = 1 ];then _register_setup_function "_setup_saslauthd" - _register_setup_function "_setup_postfix_sasl" fi if [ "$ENABLE_POSTGREY" = 1 ];then @@ -107,6 +106,7 @@ function register_functions() { _register_setup_function "_setup_postfix_hostname" _register_setup_function "_setup_dovecot_hostname" + _register_setup_function "_setup_postfix_sasl" _register_setup_function "_setup_postfix_override_configuration" _register_setup_function "_setup_postfix_sasl_password" _register_setup_function "_setup_security_stack" @@ -595,11 +595,21 @@ function _setup_postgrey() { function _setup_postfix_sasl() { + if [[ ${ENABLE_SASLAUTHD} == 1 ]];then [ ! -f /etc/postfix/sasl/smtpd.conf ] && cat > /etc/postfix/sasl/smtpd.conf << EOF pwcheck_method: saslauthd mech_list: plain login EOF - return 0 + fi + + # cyrus sasl or dovecot sasl + if [[ ${ENABLE_SASLAUTHD} == 1 ]] || [[ ${SMTP_ONLY} == 0 ]];then + sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = yes|g' /etc/postfix/main.cf + else + sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = no|g' /etc/postfix/main.cf + fi + + return 0 } function _setup_saslauthd() { diff --git a/test/email-templates/smtp-only.txt b/test/email-templates/smtp-only.txt new file mode 100644 index 00000000..220ace15 --- /dev/null +++ b/test/email-templates/smtp-only.txt @@ -0,0 +1,8 @@ +HELO mail.localhost +MAIL FROM: test@localhost +RCPT TO: user2@external.tld +DATA +This is a test mail. + +. +QUIT diff --git a/test/tests.bats b/test/tests.bats index e4199259..18240d92 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -331,6 +331,19 @@ load 'test_helper/bats-assert/load' assert_output 1 } +@test "checking smtp_only: mail send should work" { + run docker exec mail_smtponly /bin/sh -c "postconf -e smtp_host_lookup=no" + assert_success + run docker exec mail_smtponly /bin/sh -c "/etc/init.d/postfix reload" + assert_success + run docker exec mail_smtponly /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-only.txt" + assert_success + run docker exec mail_smtponly /bin/sh -c 'grep -cE "to=.*status\=sent" /var/log/mail/mail.log' + [ "$status" -ge 0 ] +} + + + # # accounts #