5

我想使用我的主机后缀安装从我的 Alpine-PHP-Fpm 容器发送邮件。

回顾

PHP-Fpm 容器 -> Sendmail -> 主机上的 PostFix -> 通过 SMTP 发送

但我明白了

sendmail:无法连接到远程主机(127.0.0.1):连接被拒绝

这是后缀配置:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no

smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = MYDOMAIN.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.com, localhost

# SMTP authentication settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:no-reply@MYDOMAIN.com:SECRETPSW
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
#header_size_limit = 4096000
relay_destination_concurrency_limit = 20

# Limit DOS Attacks
default_process_limit = 100
smtpd_client_connection_count_limit = 10
smtpd_client_connection_rate_limit = 30
queue_minfree = 20971520
header_size_limit = 51200
message_size_limit = 10485760
smtpd_recipient_limit = 100

# Default relayhost setting
relayhost = smtp.MYDOMAIN.com

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.18.0.3 # Fpm container IP
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 172.18.0.1 # Docker0 bridge IP
inet_protocols = all

这是 php.ini 邮件部分:

[mail function]
SMTP = localhost
smtp_port = 25
sendmail_path = "/usr/sbin/sendmail -t -i"
mail.add_x_header = On

我需要在 docker-compose 文件或主机防火墙设置中打开任何端口吗?

4

3 回答 3

3

我不确定是否使用主机的配置/后缀,但是我可以建议一个可能同样有效的替代解决方案。添加一个后缀容器并将配置从主机复制到容器:

services:
  application:
    image: some-company/some-application
    environment:
      - APPLICATION_ENV
    ports:
      - 80:80

  smtp:
    image: namshi/smtp
    environment:
      - MAILNAME
      - SMARTHOST_USER
      - SMARTHOST_PASSWORD
    volumes:
      - /etc/postfix/main.cf:/etc/postfix/main.cf
    ports:
      - 25:25

然后,您可以smtp用作您的邮件主机/传输和环境中的用户/通行证。

于 2017-08-21T14:05:17.807 回答
0

我不是容器专家,但如果我理解正确,您正在尝试访问容器内的 127.0.0.1(php.ini localhost 配置解析为 127.0.0.1),并且我认为这不是主机地址,它指向容器内部。

找出主机 IP 并在 php.ini 中进行更改:

[mail function]
SMTP = host_address
smtp_port = 25
于 2017-08-21T13:52:50.977 回答
0

我发现的最佳解决方案是安装 msmtp 并将以下内容添加到 php.ini

sendmail_path = /usr/bin/msmtp -t  --host host.docker.internal --from php@docker

现在您的邮件将被您的邮件服务器(smpt4dev 或 mailh

于 2021-05-13T09:36:38.783 回答