微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos – 配置Postfix通过端口587发送/中继电子邮件Gmail(smtp.gmail.com)

使用Centos 5.4,使用Postfix.我可以做一个
mail foo@gmail.com 
subject: blah
 test
.
Cc:

并且msg被发送到gmail,但它驻留在垃圾邮件文件夹中,这是预期的.

我的目标是能够生成电子邮件消息,并让它们出现在常规收件箱中!据我了解Postfix / Gmail,可以将Postfix配置为使用端口587通过经过身份验证的/有效用户发送/中继邮件,这将不再将邮件视为垃圾邮件.

我已经尝试了一些基于网络上不同网站/文章的参数,没有运气.一些文章,实际上似乎与其他文章冲突!我也查看了关于stacflow的帖子,但我仍然遗漏了一些东西……还与IRC(Centos / Postfix)上的一些人交谈,但仍有疑问……

所以,我再次转向Serverfault!

如果有人设法完成此任务,您是否介意发布您的main.cf,sasl-passwd以及您用来实现此功能的任何其他conf文件!如果我可以查看您的配置文件,我可以希望看到我搞砸了,并弄清楚如何纠正问题.

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

ps,如果有一个堆栈流贴片说明了我可能错过了,请随时向我指出!

-Tom

虽然我没有尝试使用提交端口(587)通过提供商进行中继,但它应该是可能的.要启用Postfix中继,您需要设置具有经过身份验证的凭据的文件,并对/etc/postfix/main.cf配置文件进行一些修改.

一个是身份验证凭据.为此我只需使用/ etc / postfix / sasl_passwd,我使用模板添加相应的行:

smtp.provider.com    smtp_user:smtp_passwd

您需要确保此文件受到保护,因此我建议root:root权限和0600权限.然后,您需要运行以下命令以root身份创建哈希映射版本.

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,因为我之前没有尝试在非认端口上执行此操作所以你必须自己尝试一下.

仅这些配置步骤就是处理我通过中央邮件服务器维护的多个服务器上的邮件转发.

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

事实证明我配置了我的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 =

接下来我们有/ 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>,delay=141,delays=110/29/0.36/1.9,dsn=2.0.0,status=sent (250 2.0.0 OK 1267759200 6sm401663ywd.11)

原文地址:https://www.jb51.cc/centos/373884.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。