虽然我没有尝试使用提交端口(587)通过提供程序进行中继,但应该可以。要使Postfix能够中继,您需要使用经过身份验证的凭据来设置文件以供使用,并对/etc/postfix/main.cf
配置文件进行一些修改。
第一个是身份验证凭据。为此,我只使用/etc/postfix/sasl_passwd
模板,使用模板添加相应的行:
smtp.provider.com smtp_user:smtp_passwd
您需要确保此文件受到保护,因此我建议对其设置root:root
所有权和0600
权限。然后,您需要运行以下命令以根目录创建哈希映射版本。
postmap hash:/etc/postfix/sasl_passwd
顺便说一句,/etc/postfix/main.cf
您可能会发现已经设置了一些值,因此需要进行相应的更改,但重要的细节如下:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_tls_security_level = may
这些将使Postfix在发送邮件时能够使用sasl_passwd文件进行身份验证。然后,您需要通过添加配置来告诉Postfix它应使用提供程序来发送邮件
relayhost = smtp.provider.com:port
默认情况下,如果您未指定,Postfix会假设使用端口25,并且过去对我有用。使用您要求的设置,您需要指定587作为端口。话虽如此,我不确定您是否需要将sasl_passwd条目修改为,smtp.provider.com:587
而不是smtp.provider.com
因为我之前没有尝试通过非默认端口进行此操作,因此您必须自己尝试一下。
这些配置步骤仅在我通过中央邮件服务器维护的几台服务器上处理邮件转发。
更新以包含完整的示例
事实证明,由于我的DSL提供程序阻止了出站端口25流量,因此我已将我的Ubuntu(基于Debian的)笔记本电脑配置为在我的电子邮件提供程序(非Gmail)上使用端口587。我更新为使用我的一个Gmail帐户发送邮件。我唯一需要做的改变
我模糊的私人数据,但以其他方式粘贴的,是工作的配置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 (Ubuntu)
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
# 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
smtp_tls_security_level = may
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
myhostname = example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = solitare, 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
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
接下来我们有/etc/postfix/sasl_passwd
:
smtp.gmail.com:587 myusername@gmail.com:mypassword
然后,我运行以下SMTP会话:
jbouse@solitare:~$ telnet localhost 25
Trying 127.0.0.1...
Connected to solitare.
Escape character is '^]'.
220 example.com ESMTP Postfix (Ubuntu)
helo localhost
250 example.com
mail from: jbouse@example.com
250 2.1.0 Ok
rcpt to: myotherusername@gmail.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
To: myotherusername@gmail.com
From: jbouse@example.com
Subject: Testing Postfix smarthost via Gmail
this is just a test
.
250 2.0.0 Ok: queued as 6269B280191
quit
221 2.0.0 Bye
Connection closed by foreign host.
然后,我登录我的myotherusername
Gmail帐户并阅读以下消息:
Return-Path: <myotherusername@gmail.com>
Received: from example.com (mydslproviderhostname.net [x.x.x.229])
by mx.google.com with ESMTPS id 6sm401663ywd.11.2010.03.04.19.19.58
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Thu, 04 Mar 2010 19:19:58 -0800 (PST)
Sender: "Jeremy Bouse" <myotherusername@gmail.com>
Received: from localhost (solitare [127.0.0.1])
by example.com (Postfix) with SMTP id 6269B280191
for <myotherusername@gmail.com>; Thu, 4 Mar 2010 22:17:39 -0500 (EST)
To: myotherusername@gmail.com
From: jbouse@example.com
Subject: Testing Postfix smarthost via Gmail
Message-Id: <20100305031745.6269B280191@example.com>
Date: Thu, 4 Mar 2010 22:17:39 -0500 (EST)
this is just a test
现在已经证明了我作为系统管理员的13年没有浪费,我已经从我的笔记本电脑通过Gmail发送了电子邮件,而无需像其他人那样生成自签名的x.509证书。的关键添加项/etc/postfix/main.cf
是smtp_tls_security_level设置,该设置可以告诉Postfix 如果它支持TLS,则在连接到另一个MTA时可以发出STARTTLS命令。如果您忘记了smtp_tls_security_level设置,则可能会看到/var/log/mail.log
以下内容:
Mar 4 22:10:58 solitare postfix/smtp[19873]: 20E07280191: to=<myotherusername@gmail.com>, relay=smtp.gmail.com[74.125.47.109]:587, delay=38, delays=38/0.03/0.08/0.01, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.47.109] said: 530 5.7.0 Must issue a STARTTLS command first. 20sm399188ywh.48 (in reply to MAIL FROM command))
但是,正确设置后,您应该会看到以下内容:
Mar 4 22:20:00 solitare postfix/smtp[20313]: 6269B280191: to=<myotherusername@gmail.com>, relay=smtp.gmail.com[74.125.47.109]:587, delay=141, delays=110/29/0.36/1.9, dsn=2.0.0, status=sent (250 2.0.0 OK 1267759200 6sm401663ywd.11)