configurationPostfix通过端口587发送/转发电子邮件Gmail(smtp.gmail.com)

使用Centos 5.4和Postfix。 我可以做一个

mail foo@gmail.com subject: blah test . Cc: 

和味精发送到Gmail,但它驻留在垃圾邮件文件夹,这是预期的。

我的目标是能够生成电子邮件消息,并让他们出现在常规的收件箱! 据我了解Postfix / Gmail,有可能configurationPostfix发送/中继邮件通过authentication/有效的用户使用端口587,这将不再被视为垃圾邮件。

我已经尝试了一些基于不同网站/文章的参数,没有运气。 一些文章,其实似乎与其他文章冲突! 我也仔细研究过这个stacflowpost,但是我还是错过了一些东西……还谈到了一些关于IRC(Centos / Postfix)的人,仍然有问题。

所以,我再次转向Serverfault!

如果有人设法做到这一点,你会介意发布你的main.cf,sasl-passwd以及其他任何你使用的conf文件来完成这个工作! 如果我可以查看你的configuration文件,我可以希望看到我搞砸了,并找出如何纠正这个问题。

感谢您阅读本文,以及您提供的任何帮助/指示!

ps,如果有一个stackflow发帖说这个,我可能错过了,随时向我指出!

-Tom

虽然我没有尝试通过使用提交端口(587)的提供商进行中继,但应该是可以的。 要启用Postfix中继,您需要设置一个带有authentication凭证的文件,并对/etc/postfix/main.cfconfiguration文件进行一些修改。

首先是身份validation凭证。 为此我简单地使用/etc/postfix/sasl_passwd ,我使用模板添加适当的行:

 smtp.provider.com smtp_user:smtp_passwd 

你要确保这个文件是受保护的,所以我build议root:root权限和0600权限被设置。 然后,您将需要运行以下命令以root用户身份创build哈希映射版本。

 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文件进行身份validation。 然后你需要告诉Postfix它应该使用提供者通过添加configuration来发送邮件

 relayhost = smtp.provider.com:port 

默认情况下,如果您没有指定,Postfix将假定端口为25,这在过去已经适用于我。 根据您的要求设置,您需要指定587作为端口。 与此说,我不知道你是否需要修改sasl_passwd项为smtp.provider.com:587而不是简单的smtp.provider.com因为我还没有尝试通过非默认端口所以你必须自己尝试。

这些configuration步骤本身就是在我通过中央邮件服务器维护的几台服务器上处理邮件转发。

更新以包含完整的工作示例

事实上,我已经configuration我的Ubuntu(基于Debian的)笔记本电脑使用我的电子邮件提供商端口587(不Gmail),因为我的DSL提供商阻止出站端口25的stream量。 我更新了使用我的一个Gmail帐户发送邮件。 我需要做的唯一的改变

我模糊了私人数据,但粘贴为Postfix的工作configuration。

首先我们有/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 [email protected]: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: [email protected] 250 2.1.0 Ok rcpt to: [email protected] 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> To: [email protected] From: [email protected] 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. 

然后,我login到myotherusername Gmail帐户并阅读消息:

 Return-Path: <[email protected]> Received: from example.com (mydslproviderhostname.net [xxx229]) 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" <[email protected]> Received: from localhost (solitare [127.0.0.1]) by example.com (Postfix) with SMTP id 6269B280191 for <[email protected]>; Thu, 4 Mar 2010 22:17:39 -0500 (EST) To: [email protected] From: [email protected] Subject: Testing Postfix smarthost via Gmail Message-Id: <[email protected]> Date: Thu, 4 Mar 2010 22:17:39 -0500 (EST) this is just a test 

现在已经显示了我作为系统pipe理员的13年没有浪费,我从我的笔记本电脑通过Gmail发送电子邮件,而不需要像其他人会告诉你的那样生成一个自签名的x.509证书。 /etc/postfix/main.cf的关键是smtp_tls_security_level设置, 可以告诉Postfix在连接到另一个MTA(如果它支持TLS)时发出STARTTLS命令是可以的。 如果您忘记了smtp_tls_security_level设置,则可能会在/var/log/mail.log看到以下行中的条目:

 Mar 4 22:10:58 solitare postfix/smtp[19873]: 20E07280191: to=<[email protected]>, 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=<[email protected]>, 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)