如何将 Postfix 端口从 25 更改为 587?

如何将 Postfix 端口从 25 更改为 587?

我对 Unix 和 CLI 完全是菜鸟。在谷歌搜索了近 6 个小时后,我才知道我应该将 postfix 端口从 25 编辑为 587,以使 PHP mail() 函数正常工作。下面是我得到的解决方案http://www.linuxmail.info/postfix-change-port/但我不知道如何改变它。正如已经说过的,我是个菜鸟。任何与此相关的帮助都将不胜感激。

更新1:

Grawity 解决方案给出了以下错误。

May  7 00:42:39 Ibrahim-Armars-MacBook-Pro postfix/pickup[4169]: DE2073F07C1: uid=501 from=<azhararmar>
May  7 00:42:39 Ibrahim-Armars-MacBook-Pro postfix/master[4185]: fatal: open lock file pid/master.pid: unable to set exclusive lock: Resource temporarily unavailable
May  7 00:42:39 Ibrahim-Armars-MacBook-Pro postfix/cleanup[4177]: DE2073F07C1: message-id=<[email protected]>
May  7 00:42:39 Ibrahim-Armars-MacBook-Pro postfix/qmgr[4168]: DE2073F07C1: from=<[email protected]>, size=525, nrcpt=1 (queue active)
May  7 00:42:40 Ibrahim-Armars-MacBook-Pro postfix/smtp[4179]: DE2073F07C1: to=<[email protected]>, relay=smtp.gmail.com[74.125.155.109]:587, delay=0.8, delays=0.01/0/0.79/0, dsn=4.7.5, status=deferred (TLS is required, but our TLS engine is unavailable)
May  7 00:42:41 Ibrahim-Armars-MacBook-Pro postfix/pickup[4169]: 5F2FC3F07C4: uid=501 from=<azhararmar>
May  7 00:42:41 Ibrahim-Armars-MacBook-Pro postfix/cleanup[4177]: 5F2FC3F07C4: message-id=<[email protected]>
May  7 00:42:41 Ibrahim-Armars-MacBook-Pro postfix/qmgr[4168]: 5F2FC3F07C4: from=<[email protected]>, size=525, nrcpt=1 (queue active)
May  7 00:42:42 Ibrahim-Armars-MacBook-Pro postfix/smtp[4179]: 5F2FC3F07C4: to=<[email protected]>, relay=smtp.gmail.com[74.125.155.109]:587, delay=0.79, delays=0.01/0/0.78/0, dsn=4.7.5, status=deferred (TLS is required, but our TLS engine is unavailable)
May  7 00:42:50 Ibrahim-Armars-MacBook-Pro postfix/master[4190]: fatal: open lock file pid/master.pid: unable to set exclusive lock: Resource temporarily unavailable

更新2:

May  7 01:10:02 Ibrahim-Armars-MacBook-Pro postfix/master[4472]: fatal: open lock file pid/master.pid: unable to set exclusive lock: Resource temporarily unavailable
May  7 01:10:02 Ibrahim-Armars-MacBook-Pro postfix/pickup[4419]: 357F73F090F: uid=501 from=<azhararmar>
May  7 01:10:02 Ibrahim-Armars-MacBook-Pro postfix/cleanup[4430]: 357F73F090F: message-id=<[email protected]>
May  7 01:10:02 Ibrahim-Armars-MacBook-Pro postfix/qmgr[4420]: 357F73F090F: from=<[email protected]>, size=525, nrcpt=1 (queue active)
May  7 01:10:03 Ibrahim-Armars-MacBook-Pro postfix/smtp[4448]: certificate verification failed for smtp.gmail.com[74.125.155.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority

答案1

根据您对其他答案的评论,您需要配置 Postfix 以使用 Gmail 作为中继主机。有许多教程在互联网上;这是一个简短的版本。

注意:使用此配置,所有邮件都必须使用您的 Gmail 地址作为“发件人”来发送。

  1. 撤消对 的所有更改master.cf

  2. 在 中main.cf添加以下设置:

    # This tells Postfix to hand off all messages to Gmail, and never do direct delivery.
    relayhost = [smtp.gmail.com]:587
    
    # This enables TLS (SMTPS) certificate verification, because Gmail has a valid one.
    smtp_tls_security_level = verify
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
    smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
    
    # This tells Postfix to provide the username/password when Gmail asks for one.
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    
  3. 在 中/etc/postfix/sasl_passwd,添加您的 Gmail 用户名和密码,如下所示:

    [smtp.gmail.com]:587    [email protected]:mypassword
    
  4. sasl_passwd文件编译成数据库:

    postmap /etc/postfix/sasl_passwd
    
  5. 最后重新加载Postfix的主配置:

    postfix reload
    

答案2

如果你仅有的希望它在端口 587 上运行(我不确定你是否想;我认为你希望它在 25587),然后在 /etc/postfix/master.cf 中找到如下行:

smtp      inet  n       -       n       -       -       smtpd

并将其更改为如下所示:

587      inet  n       -       n       -       -       smtpd

如果您希望它在两个端口上运行,那么请在第一行后添加第二行,而不是替换它。

答案3

我要感谢用户1686他们很棒的小教程!经过几个小时的搜索,我终于能够解决我的 Postfix smtp 发送问题。

对我来说,这个问题很简单;我只需要添加:587文件中还包含端口信息/etc/postfix/sasl_passwd。如果没有这些信息,我的电子邮件中继主机将拒绝建立任何连接。以下命令应该是一步到位的最简单方法:

echo "[smtp.xyz.com]:587 [email protected]:password" > /etc/postfix/sasl_passwd

使其仅限 root 用户:

chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd

嗯,大多数其他 Postfix 教程都没有提到这个非常重要的端口相关事实!有些教程只说明relayhost = [smtp.xyz.com]:587有时必须添加端口信息main.cf。嗯,在我的例子中,文件中还必须包含必要的端口信息sasl_passwd config

我的其他后缀参数是:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = may
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_mandatory_ciphers = high
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt

相关内容