我正在尝试从我的 ubuntu 服务器的命令行发送电子邮件。因此我开始在本地机器上而不是服务器上配置 postfix。基本上这些是我遵循的步骤:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
sudo vim /etc/postfix/main.cf
在文件中添加以下几行:
relayhost = [smtp.gmail.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_use_tls = yes
sudo vim /etc/postfix/sasl_passwd
在文件中添加了这一行[smtp.gmail.com]:587 [email protected]:PASSWORD
权限并更新了 postfix 配置文件。
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
重新加载 POSTFIX:sudo /etc/init.d/postfix reload
然后在我的终端上运行以下命令:
echo "Test mail from postfix" | mail -s "Test Postfix" [email protected]
但没有收到邮件。所以我检查了日志文件,在那里我找到了下面的堆栈跟踪:
postfix/pickup[26530]: A62AF2E29B4: uid=1000 from=<z@mylaptop>
postfix/cleanup[27372]: A62AF2E29B4: message-id=<20160428114754.A62AF2E29B4@mylaptop>
postfix/qmgr[26529]: A62AF2E29B4: from=<z@mylaptop>, size=365, nrcpt=1 (queue active)
postfix/smtp[27379]: cannot load Certificate Authority data: disabling TLS support
postfix/smtp[27379]: warning: TLS library problem: error:02001002:system library:fopen:No such file or directory:bss_file.c:169:fopen('/etc/postfix/cacert.pem','r'):
postfix/smtp[27379]: warning: TLS library problem: error:2006D080:BIO routines:BIO_new_file:no such file:bss_file.c:172:
postfix/smtp[27379]: warning: TLS library problem: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib:by_file.c:274:
postfix/smtp[27379]: connect to smtp.gmail.com[2404:6800:4003:c02::6d]:587: Network is unreachable
postfix/smtp[27379]: A62AF2E29B4: to=<[email protected]>, relay=smtp.gmail.com[74.125.68.108]:587, delay=1.4, delays=0.01/0.02/1/0.34, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.68.108] said: 530 5.7.0 Must issue a STARTTLS command first. g70sm14489231pfb.7 - gsmtp (in reply to MAIL FROM command))
postfix/cleanup[27372]: 5BFDF2E2B48: message-id=<20160428114756.5BFDF2E2B48@mylaptop>
postfix/bounce[27383]: A62AF2E29B4: sender non-delivery notification: 5BFDF2E2B48
postfix/qmgr[26529]: 5BFDF2E2B48: from=<>, size=2239, nrcpt=1 (queue active)
postfix/qmgr[26529]: A62AF2E29B4: removed
postfix/local[27384]: 5BFDF2E2B48: to=<z@mylaptop>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
postfix/qmgr[26529]: 5BFDF2E2B48: removed
答案1
postfix/smtp[27379]: cannot load Certificate Authority data: disabling TLS support
postfix/smtp[27379]: warning: TLS library problem: error:02001002:system library:fopen:No such file or directory:bss_file.c:169:fopen('/etc/postfix/cacert.pem','r'):
安装认证机构的证书 - 它们认证其他证书 => 安装名为的包ca 证书在 debian/ubuntu 上。