问题:创建一个联系表单,让网站用户提交发送到电子邮件的消息。使用 phpmail()
和 Postfix。使用/理解 Postfix 时遇到问题?设置肯定不正确 - 我无法让电子邮件显示在外部邮件服务器上()。echo "hello, world" | mail [email protected]
设置:在非专用的 Raspberry Pi 3B+ 上运行 Postfix,无需注册域名(动态 DNS)。请参阅没有真实互联网主机名的主机上的 Postfix以及 README.html 的其他部分...我不确定这里适用什么。我不需要 Postfix 来接收邮件?注意:在 Postfix 设置期间,我实际上输入的mail.example.com
是 FQDN。据我所知,它可能是一个smtp.gmail.com
用作通过 Postfix 进行外部 MTA? 这就是我尝试遵循的教程...所以我有它描述的 SASL 文件。在设置方面我还没有做太多其他的事情。使用telnet smtp.gmail.com 25
和telnet smtp.gmail.com 587
都会导致超时。
配置:
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 (Raspbian)
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 = no
# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2
# 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.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mail.example.com, raspberrypi, localhost.localdomain, localhost
relayhost = [smtp.gmail.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
# Enable SASL auth
smtp_sasl_auth_enable = yes
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous
# Directory of sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# Directory of ca-certs
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
还:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.9 (stretch)
Release: 9.9
Codename: stretch
$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN 31792/sendmail: MTA
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 31792/sendmail: MTA
参考:有关于使用 Raspberry Pi 的讨论sendmail
这里(我没有尝试使用,sendmail
但考虑它的设置也许会有所帮助)。
先前的一个答案建议“配置 postfix 使用 gmail 发送邮件看起来很有希望。大多数公共电子邮件系统(gmail、outlook 等)要么不允许您进行 smtp 中继,要么您需要配置其安全性。没有这些,垃圾邮件发送者将完全淹没他们的邮件服务器!”
任何进一步的想法都将受到赞赏。