我希望非本地电子邮件通过我的个人Google帐户和本地电子邮件转发给当地用户。 我的configuration是:/ etc / postfix / transport
* smtp:[smtp.gmail.com]:587
和/etc/postfix/main.cf
[root@media postfix]# cat main.cf # This file contains only the parameters changed from a default install # see /etc/postfix/main.cf.dist for a commented, fuller version of this file. transport_maps = hash:/etc/postfix/transport smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_mechanism_filter = plain, login smtp_sasl_security_options = noanonymous smtp_use_tls = yes
/等/后缀/ sasl_passwd:
[smtp.google.com]:587 [email protected]:mypass
而我运行后:
# postmap transport && postmap sasl_passwd systemctl restart postfix.service
所以,现在我的服务器尝试连接到gmail MX(没有成功,但不提供电子邮件本地
来自journalctl的日志:
Jul 06 18:38:01 media postfix/pickup[31431]: 30714960F8: uid=0 from=<root> Jul 06 18:38:01 media postfix/cleanup[31641]: 30714960F8: message- id=<[email protected]> Jul 06 18:38:01 media postfix/qmgr[31432]: 30714960F8: from=<[email protected]>, size=436, nrcpt=1 (queue active) Jul 06 18:38:01 media postfix/smtp[31643]: connect to smtp.gmail.com[2a00:1450:4008:c01::6c]:587: Network is unreachable Jul 06 18:38:01 media postfix/smtp[31643]: 30714960F8: to=<[email protected]>, relay=smtp.gmail.com[173.194.69.108]:587, delay=0.7, delays=0.03/0.04/0.55/0.07, ...M command)) Jul 06 18:38:02 media postfix/cleanup[31641]: 0B85D960F9: message-id=<[email protected]> Jul 06 18:38:02 media postfix/qmgr[31432]: 0B85D960F9: from=<>, size=2555, nrcpt=1 (queue active) Jul 06 18:38:02 media postfix/bounce[31646]: 30714960F8: sender non-delivery notification: 0B85D960F9 Jul 06 18:38:02 media postfix/qmgr[31432]: 30714960F8: removed Jul 06 18:38:02 media postfix/smtp[31643]: connect to smtp.gmail.com[2a00:1450:4008:c01::6d]:587: Network is unreachable Jul 06 18:38:02 media postfix/smtp[31643]: 0B85D960F9: to=<[email protected]>, relay=smtp.gmail.com[173.194.69.109]:587, delay=0.59, delays=0.02/0.01/0.51/0.06,...M command)) Jul 06 18:38:02 media postfix/qmgr[31432]: 0B85D960F9: removed Jul 06 18:38:40 media auth[31778]: pam_tcb(dovecot:auth): Authentication passed for media from (uid=0) Jul 06 18:38:40 media dovecot[1442]: pop3-login: Login: user=<media>, method=PLAIN, rip=192.168.0.2, lip=192.168.0.7, mpid=31779, secured, session=<VZaXcdrgpADAqAAC> Jul 06 18:38:40 media dovecot[1442]: pop3(media): Disconnected: Logged out top=0/0, retr=0/0, del=0/0, size=0 Jul 06 18:38:58 media postfix/pickup[31431]: CD15D960F8: uid=0 from=<root> Jul 06 18:38:58 media postfix/cleanup[31641]: CD15D960F8: message-id=<[email protected]> Jul 06 18:38:58 media postfix/qmgr[31432]: CD15D960F8: from=<[email protected]>, size=430, nrcpt=1 (queue active) Jul 06 18:38:59 media postfix/smtp[31643]: CD15D960F8: to=<[email protected]>, relay=smtp.gmail.com[173.194.69.108]:587, delay=0.63, delays=0.02/0/0.54/0.06, dsn=5.5....M command)) Jul 06 18:38:59 media postfix/cleanup[31641]: BAB0E960F9: message-id=<[email protected]> Jul 06 18:38:59 media postfix/qmgr[31432]: BAB0E960F9: from=<>, size=2541, nrcpt=1 (queue active) Jul 06 18:38:59 media postfix/bounce[31646]: CD15D960F8: sender non-delivery notification: BAB0E960F9 Jul 06 18:38:59 media postfix/qmgr[31432]: CD15D960F8: removed Jul 06 18:39:00 media postfix/smtp[31643]: BAB0E960F9: to=<[email protected]>, relay=smtp.gmail.com[173.194.69.109]:587, delay=0.66, delays=0.02/0.01/0.56/0.07,...M command)) Jul 06 18:39:00 media postfix/qmgr[31432]: BAB0E960F9: removed
任何帮助,使其工作?
您必须在Postfix的SMTP客户端中启用TLS ,因为Google需要它。 这在消息Must issue a STARTTLS command由他们Must issue a STARTTLS command 。
在/etc/postfix/main.cf ,你需要这样的东西:
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
然后在/etc/postfix/tls_policy :
[smtp.gmail.com]:587 encrypt
tls_policy的左侧必须与main.cf的relayhost条目完全相同。
请记住,在创build或根据需要更改后,在/etc/postfix/tls_policy上运行/etc/postfix/tls_policy 。
你可以在Postfix的TLS文档中find更多的细节。
请参阅这些链接
这是我使用的过程:
sudo apt-get install postfix.
如果询问您安装了哪种邮件服务器,请select无configuration(第一个选项)
sudo nano /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 # listen on localhost only inet_interfaces = 127.0.0.1 smtpd_banner = $myhostname ESMTP $mail_name 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 relayhost = [smtp.gmail.com]:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous
保存文件,现在我们用用户名和密码创build文件
sudo nano /etc/postfix/sasl_passwd
并粘贴在下面做出所需的replace
[smtp.gmail.com]:587 [email protected]:password
保存它,并在命令提示符下
sudo postmap /etc/postfix/sasl_passwd
然后
chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
最后,
sudo service postfix restart
请注意,一旦您成功testing了电子邮件系统,您可以在sasl_passwd中删除/模糊密码。
用你的应用程序进行testing。 如果遇到麻烦,请检查/var/log/mail.log您可以通过apt-get install mail-utils来安装邮件程序。 你可以再testing一下
echo “this is a test” | mailx -s “This is the subject” [email protected]
最后
跑
newaliases
制作一个/etc/aliases.db文件。 如果你不这样会logging很多关于它的错误到/var/log/mail.err如果你得到SASL错误(postfix)检查主机名在/ etc / hosts和/ etc / hostname如果postfix抱怨没有能够中继给定的主机/ IP地址(后缀)添加到/etc/postfix/main.cf
mynetworks = 10.0.0.0/8
这将允许任何拥有10.0.0.0地址的人连接,显然你应该尽可能地减less这种情况,无论是通过限制networking,还是使用任何防火墙或安全策略
首先,请确保首先检查Google的身份validation方法:
https://www.google.com/settings/security/lesssecureapps
如果该页面不适用于您的帐户,则域pipe理员将为所有用户禁用此设置(默认)。
当您在google admin的中继SMTP中将您的IP /范围列入白名单时,您可以使用此设置发送电子邮件
relayhost = [smtp-relay.gmail.com]:587 smtp_use_tls = yes smtp_tls_loglevel=1 smtp_tls_security_level=encrypt smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = login, plain smtp_tls_CApath = /etc/ssl/certs smtp_sasl_tls_security_options = noanonymous
但是,当Allow less secure apps: OFF我总是得到这些消息:
(SASL authentication failed; server smtp-relay.gmail.com[173.194.204.28] said: 534-5.7.14 ... Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14 Learn more at?534 5.7.14 https://support.google.com/mail/answer/78754 g133sm1077601qkb.1 - gsmtp)
但消息仍然传递(这有点奇怪),虽然它需要更长的时间才能收到消息。