我正在尝试在Docker容器中设置postfix 。 在启动时,我正在运行以下安装脚本:
# Install postfix/mailutils with configuration options echo "postfix postfix/mailname string $MAILSERVER:587" | debconf-set-selections echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections apt-get install -yqq postfix apt-get install -yqq mailutils # Setup credentials for SMTP server mkdir -p /etc/postfix/sasl touch /etc/postfix/sasl/sasl_passwd /etc/postfix/main.cf echo "[$MAILSERVER]:587 $EMAIL_USER:$EMAIL_PASSWORD" >> /etc/postfix/sasl/sasl_passwd chown -R postfix:postfix /etc/postfix chmod 600 /etc/postfix/sasl/sasl_passwd postmap /etc/postfix/sasl/sasl_passwd # Create postfix configuration echo "relayhost = [$MAILSERVER]:587" >> /etc/postfix/main.cf echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd" >> /etc/postfix/main.cf echo "smtp_sasl_security_options = noanonymous" >> /etc/postfix/main.cf echo "smtp_use_tls = yes" >> /etc/postfix/main.cf echo "debug_peer_list = $MAILSERVER" >> /etc/postfix/main.cf echo "debug_peer_level = 3" >> /etc/postfix/main.cf echo "smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt" >> /etc/postfix/main.cf # Reload postfix for new configurations to take effect postfix reload /etc/init.d/postfix restart
运行脚本后,我在/etc/postfix/main.cf的结尾处添加了以下内容:
# Use gmail relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes debug_peer_list=smtp.gmail.com debug_peer_level=3 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
我已经确认/etc/postfix/sasl_passwd和/etc/ssl/certs/ca-certificates.crt存在,但我不断收到:
postfix/bounce[1052]: error: unsupported dictionary type: smtp.gmail.com
注:我看过类似标题的问题,但发布的解决scheme对我的设置没有帮助。
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
在这里,您使用Berkeley DB作为Postfix查找表types :
hash基于散列的索引文件types。 这仅在支持Berkeley DB数据库的系统上可用。 公共数据库文件是使用
postalias(1)postmap(1)或postalias(1)命令创build的,私有数据库由Postfix守护进程维护。 在hash:table中使用的数据库名称是没有.db后缀的数据库文件名。
因此, /etc/postfix/sasl_passwd的存在与/etc/postfix/sasl_passwd.db的存在是不相关的, /etc/postfix/sasl_passwd是通过postmap /etc/postfix/sasl_passwd 。 但是,如果你错过了那个文件,我相信你应该直接告诉它一个错误。
这可能是因为你的Postfix缺lessBerkeley DB支持。 在Debian上,默认的postfix包是用这个支持构build的,你可以使用postconf -m来检查它是否有。 如果列表不包含hash和btree ,则表示缺less支持。 那么,有关更多信息,请参阅Postfix Berkeley DB Howto 。
我解决了这个问题,但我不确定是什么原因造成的。
在安装过程中,gmail SMTP服务器被添加到main.cf的值mydestination中。
我结束了在我的Dockerfile运行以下脚本来修复该值:
sed -i '/mydestination =/d' /etc/postfix/main.cf echo "mydestination = localhost.localdomain, localhost" >> /etc/postfix/main.cf