我正在尝试通过 php 发送邮件,在带有 postfix 的 Debian 服务器上,当我在服务器中运行以下脚本时,代码告诉我电子邮件已成功发送,这是我的代码:
<?php
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed¦</p>");
}
?>
但是,当我检查收件人的邮件时,收件箱中没有已发送的邮件。我应该在 postfix 的配置中更改哪些文件?
我发布一些我的 postfix 配置文件:
/etc/postfix/main.cf
#See /usr/share/postfix/main.cf.dist for a commented, more complete version #Debian specific: Specifying a file name will cause the first #line of that file to be used as the name. The Debian default #is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no #appending .domain is the MUA's job. append_dot_mydomain = no #Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = /usr/share/doc/postfix #TLS parameters 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 #See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for #information on enabling SSL in the smtp client. myhostname = simbiosis_ucv alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = simbiosis_ucv, localhost.localdomain, , localhost relayhost = [gmail-smtp-msa.l.google.com]:587 mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all html_directory = /usr/share/doc/postfix/html smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes smtp_tls_CAfile = /etc/postfix/cacert.pem
/etc/hosts
127.0.0.1 localhost 190.169.94.56 tesisvergaraomana tesisvergaraomana The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
/var/log/mail.log
Apr 5 16:21:27 tesisvergaraomana postfix/smtp[10172]: 3427C22E015: to= <[email protected]>, relay=gmail-smtp-msa.l.google.com[74.125.196.109]:587, delay=0.54, delays=0.1/0.01/0.37/0.07, dsn=5.7.0, status=bounced (host gmail-smtp-msa.l.google.com[74.125.196.109] said: 530 5.7.0 Must issue a STARTTLS command first. t9sm11828331yhg.18 - gsmtp (in reply to MAIL FROM command)) Apr 5 16:21:27 tesisvergaraomana postfix/cleanup[10157]: CD71422E016: message-id=<20140405205127.CD71422E016@simbiosis_ucv> Apr 5 16:21:27 tesisvergaraomana postfix/bounce[10173]: 3427C22E015: sender non-delivery notification: CD71422E016 Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: CD71422E016: from=<>, size=2403, nrcpt=1 (queue active) Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: 3427C22E015: removed Apr 5 16:21:27 tesisvergaraomana postfix/local[10159]: CD71422E016: to=<root@simbiosis_ucv>, relay=local, delay=0.11, delays=0.05/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:21:27 tesisvergaraomana postfix/qmgr[25492]: CD71422E016: removed Apr 5 16:39:01 tesisvergaraomana postfix/pickup[10185]: BB34622E016: uid=0 from=<root> Apr 5 16:39:01 tesisvergaraomana postfix/cleanup[10333]: BB34622E016: message-id=<20140405210901.BB34622E016@simbiosis_ucv> Apr 5 16:39:01 tesisvergaraomana postfix/qmgr[25492]: BB34622E016: from=<root@simbiosis_ucv>, size=785, nrcpt=1 (queue active) Apr 5 16:39:01 tesisvergaraomana postfix/local[10335]: BB34622E016: to=<root@simbiosis_ucv>, orig_to=<root>, relay=local, delay=0.2, delays=0.13/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:39:01 tesisvergaraomana postfix/qmgr[25492]: BB34622E016: removed Apr 5 16:40:01 tesisvergaraomana postfix/pickup[10185]: D29A222E016: uid=104 from=<smmsp> Apr 5 16:40:01 tesisvergaraomana postfix/cleanup[10333]: D29A222E016: message-id=<20140405211001.D29A222E016@simbiosis_ucv> Apr 5 16:40:01 tesisvergaraomana postfix/qmgr[25492]: D29A222E016: from=<smmsp@simbiosis_ucv>, size=696, nrcpt=1 (queue active) Apr 5 16:40:01 tesisvergaraomana postfix/local[10335]: D29A222E016: to=<root@simbiosis_ucv>, orig_to=<root>, relay=local, delay=0.19, delays=0.13/0/0/0.06, dsn=2.0.0, status=sent (delivered to command: procmail -a "$EXTENSION") Apr 5 16:40:01 tesisvergaraomana postfix/qmgr[25492]: D29A222E016: removed
/etc/resolv.conf
nameserver 190.169.94.5
后配置-n
alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases append_dot_mydomain = no biff = no config_directory = /etc/postfix html_directory = /usr/share/doc/postfix/html inet_interfaces = all mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 mydestination = simbiosis_ucv, localhost.localdomain, , localhost myhostname = simbiosis_ucv mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 readme_directory = /usr/share/doc/postfix recipient_delimiter = + relayhost = [gmail-smtp-msa.l.google.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd smtp_sasl_security_options = noanonymous smtp_tls_CAfile = /etc/postfix/cacert.pem smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache smtp_use_tls = yes smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_use_tls = yes
我的目标是获得一个功能齐全的邮件服务器,它可以将电子邮件发送到所有地址
host: strix.ciens.ucv.ve
port: 465
domain: ciens.ucv.ve
username: [email protected]
active ssl
有人能告诉我配置中需要更改什么吗?我需要安装另一个工具吗?希望就这些。如果您还需要其他东西,请告诉我。
答案1
根据日志条目:
4 月 5 日 16:21:27 tesisvergaraomana postfix/smtp[10172]: 3427C22E015: to=,relay=gmail-smtp-msa.l.google.com[74.125.196.109]:587,delay=0.54,delays=0.1/0.01/0.37/0.07,dsn=5.7.0,status=bounced(主机 gmail-smtp-msa.l.google.com[74.125.196.109] 说:530 5.7.0 必须先发出 STARTTLS 命令。t9sm11828331yhg.18 - gsmtp(回复 MAIL FROM 命令))
显然你的 tls 配置有问题。
首先,您应该设置一个“合适的”证书。如何为自签名证书执行此操作,您可以在此处查看,例如: 创建 Postfix 证书
然后使用配置选项:
smtpd_use_tls = 是
如果你查阅一下文献,你会发现以下内容:
smtp_use_tls(默认值:否)机会模式:当远程 SMTP 服务器宣布支持 STARTTLS 时使用 TLS,否则以明文形式发送邮件。注意:即使未配置,某些 SMTP 服务器也会提供 STARTTLS。对于 Postfix < 2.3,如果 TLS 握手失败,并且没有其他服务器可用,则传递将被推迟,邮件将保留在队列中。如果您担心这一点,请改用 smtp_tls_per_site 功能。
Postfix 2.2 中提供了此功能
及更高版本。对于 Postfix 2.3 及更高版本,请改用 smtp_tls_security_level。
smtp_tls_security_level
您可以在这里查阅 文档:http://www.postfix.org/postconf.5.html#smtp_tls_security_level
(我必须承认,我个人使用smtpd_use_tls = yes
自签名证书选项时没有遇到任何问题)
您可以在这里找到有关 postfix 和 tls 的更多信息: http://www.postfix.org/TLS_README.html
此外,您似乎正在使用中继主机 ( relayhost = [gmail-smtp-msa.l.google.com]:587
)。这意味着您发送的所有邮件都通过中继主机路由。在大多数情况下,只有使用正确的 tls 连接才能访问端口 587。因此,您需要一个有效的 tls 设置,如果您需要在 google 中继主机上进行身份验证,则必须设置其他配置选项。
请看这里: http://baldric.net/upstream-authentication-with-tls-on-postfix/
此外,您还必须验证 postfix 是否可以访问所有必要的文件。我很长时间没有使用 Debian,但据我所知,它可以在chroot
Debian 的 ed 环境中运行。因此,请确保 postfix 可以访问所有必要的文件(在您的情况下,基本上是配置文件、证书和缓存)。
希望这能为您指明正确的方向。祝您好运。:)