問題:建立一個聯絡表單,讓網站使用者可以提交發送到電子郵件的訊息。使用 phpmail()
和 Postfix。使用/理解 Postfix 時遇到困難?設定一定不正確 - 我無法在外部郵件伺服器上顯示電子郵件 ( )。echo "hello, world" | mail [email protected]
設定:在非專用 Raspberry Pi 3B+ 上透過連接埠轉送執行 Postfix,無需註冊網域名稱(動態 DNS)。看沒有真實 Internet 主機名稱的主機上的 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 中繼,要么您需要對其安全進行設定。如果沒有這個,垃圾郵件發送者將完全淹沒他們的郵件伺服器!
任何進一步的想法表示讚賞。