tom*_*ith 9 email postfix centos gmail
使用 Centos 5.4 和 Postfix。我可以做一个
mail foo@gmail.com
subject: blah
test
.
Cc:
Run Code Online (Sandbox Code Playgroud)
并且 msg 被发送到 gmail,但它驻留在垃圾邮件文件夹中,这是意料之中的。
我的目标是能够生成电子邮件消息,并让它们出现在常规收件箱中!据我了解 Postfix/Gmail,可以将 Postfix 配置为使用端口 587 通过经过身份验证的/有效用户发送/中继邮件,这样邮件将不再被视为垃圾邮件。
我已经尝试了许多基于来自“网络”的不同站点/文章的参数,但都没有成功。有些文章,居然好像和其他文章有冲突!我也查看了关于此的 stacflow 帖子,但我仍然缺少一些东西......还在 IRC(Centos/Postfix)上与一些人交谈过,但仍然有问题......
所以,我再次转向 Serverfault!
如果有人设法做到了这一点,您是否介意发布您的 main.cf、sasl-passwd 和任何其他用于使其工作的 conf 文件!如果我可以查看您的配置文件,我希望能看到我搞砸的地方,并找出如何解决问题的方法。
感谢您阅读本文以及您提供的任何帮助/指示!
ps,如果有我可能错过的堆栈流帖子说明了这一点,请随时向我指出!
-汤姆
Jer*_*use 18
虽然我没有尝试使用提交端口 (587) 通过提供程序进行中继,但它应该是可能的。要启用 Postfix 进行中继,您需要使用经过身份验证的凭据设置一个文件,并对/etc/postfix/main.cf
配置文件进行一些修改。
第一个是身份验证凭据。为此,我只是使用/etc/postfix/sasl_passwd
我使用模板添加适当的行:
smtp.provider.com smtp_user:smtp_passwd
Run Code Online (Sandbox Code Playgroud)
您需要确保此文件受到保护,因此我建议对其设置root:root
所有权和0600
权限。然后,您需要运行以下命令以 root 身份创建哈希映射版本。
postmap hash:/etc/postfix/sasl_passwd
Run Code Online (Sandbox Code Playgroud)
这样一来,/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
Run Code Online (Sandbox Code Playgroud)
这些将使 Postfix 能够在发送邮件时使用 sasl_passwd 文件进行身份验证。然后你需要告诉 Postfix 它应该通过添加配置来使用提供者来发送邮件
relayhost = smtp.provider.com:port
Run Code Online (Sandbox Code Playgroud)
默认情况下,如果您不指定,Postfix 会假定端口为 25,这在过去对我有用。根据您请求的设置,您需要指定 587 作为端口。话虽如此,我不确定您是否需要修改 sasl_passwd 条目,smtp.provider.com:587
而不是简单地修改,smtp.provider.com
因为我之前没有尝试过通过非默认端口执行此操作,因此您必须自己尝试。
这些配置步骤单独处理我通过中央邮件服务器维护的几台服务器上的邮件转发。
更新以包含完整的工作示例
事实证明,我已将我的 Ubuntu(基于 Debian 的)笔记本电脑配置为在我的电子邮件提供商(非 Gmail)上使用端口 587,因为我的 DSL 提供商阻止了出站端口 25 流量。我更新为使用我的 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 =
Run Code Online (Sandbox Code Playgroud)
接下来我们有/etc/postfix/sasl_passwd
:
smtp.gmail.com:587 myusername@gmail.com:mypassword
Run Code Online (Sandbox Code Playgroud)
然后我运行了以下 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.
Run Code Online (Sandbox Code Playgroud)
然后我登录我的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
Run Code Online (Sandbox Code Playgroud)
现在,我作为系统管理员的 13 年没有浪费,我可以通过 Gmail 从我的笔记本电脑发送电子邮件,而无需像其他人告诉您的那样生成自签名的 x.509 证书。/etc/postfix/main.cf
对smtp_tls_security_level的关键补充是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))
Run Code Online (Sandbox Code Playgroud)
但是,正确设置后,您应该会看到以下内容:
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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
37608 次 |
最近记录: |