我有一个域example.com设置如下
无论何时服务器需要向我发送电子邮件,它都使用Postfix通过Google的SMTP服务器发送电子邮件。
这工作得很好,但服务器发送电子邮件[email protected]
。 我在Google Apps中设置了一个别名,以允许[email protected]
发送和接收邮件为[email protected]
。 我希望postfix以[email protected]
身份发送邮件,同时以[email protected]
login到Google的SMTP服务器。 简单的解决办法是打开我的服务器的另一个应用程序帐户,但这是一个小型业余爱好项目每月5美元。
但它从盒子里面出来(有一点例外,见下文)。 [email protected]它是主要电子邮件帐户的别名[email protected]
# echo "Hello world" | swaks -4 --server smtp.gmail.com:587 --from [email protected] \ --to [email protected] -tls --auth PLAIN --auth-user [email protected] \ --auth-password 1234567 --h-Subject TEST --h-From: '"Do not reply" <[email protected]>' --body - === Trying smtp.gmail.com:587... === Connected to smtp.gmail.com. <- 220 smtp.gmail.com ESMTP un6sm65521lbb.18 - gsmtp -> EHLO svn.example.net <- 250-smtp.gmail.com at your service, [77.122.73.151] <- 250-SIZE 35882577 <- 250-8BITMIME <- 250-STARTTLS <- 250-ENHANCEDSTATUSCODES <- 250-PIPELINING <- 250-CHUNKING <- 250 SMTPUTF8 -> STARTTLS <- 220 2.0.0 Ready to start TLS === TLS started with cipher TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128 === TLS no local certificate set === TLS peer DN="/C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.gmail.com" ~> EHLO svn.example.net <~ 250-smtp.gmail.com at your service, [77.122.73.151] <~ 250-SIZE 35882577 <~ 250-8BITMIME <~ 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH <~ 250-ENHANCEDSTATUSCODES <~ 250-PIPELINING <~ 250-CHUNKING <~ 250 SMTPUTF8 ~> AUTH PLAIN VhAEBMZXHN7cyxhAGFG0ub9JnLnZaGhfsuaGhhQhhLTEiNTU8Ng== <~ 235 2.7.0 Accepted ~> MAIL FROM:<[email protected]> <~ 250 2.1.0 OK un6sm65521lbb.18 - gsmtp ~> RCPT TO:<[email protected]> <~ 250 2.1.5 OK un6sm65521lbb.18 - gsmtp ~> DATA <~ 354 Go ahead un6sm65521lbb.18 - gsmtp ~> Date: Wed, 09 Mar 2016 21:15:09 +0000 ~> To: [email protected] ~> From: "Do not reply" <[email protected]> ~> Subject: TEST ~> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/ ~> ~> Hello world ~> ~> ~> . <~ 250 2.0.0 OK 1457558110 un6sm65521lbb.18 - gsmtp ~> QUIT <~ 221 2.0.0 closing connection un6sm65521lbb.18 - gsmtp === Connection closed with remote host.
例外 。
在标题中,您仍然可以看到原始发件人用户(发件人:Alex Domoradov)
Return-Path: <[email protected]> Received: from svn.example.net ([77.122.73.151]) by smtp.gmail.com with ESMTPSA id un6sm65521lbb.18.2016.03.09.13.15.10 for <[email protected]> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Mar 2016 13:15:10 -0800 (PST) Message-ID: <[email protected]> Sender: Alex Domoradov <[email protected]> Date: Wed, 09 Mar 2016 21:15:09 +0000 To: [email protected] From: "Do not reply" <[email protected]> Subject: TEST X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/ Hello world
PS您必须在帐户设置页面添加别名
所以,事实certificate,我需要做两件事才能实现。
首先,简单地在Google Appspipe理控制台中为电子邮件地址添加别名是不够的,而根据Alex的回答,在设置页面的“Send Mail As”面板中添加附加地址也是非常重要的。 如果您不这样做,Gmail会将旧地址移至额外的标题,并使用您授权使用的地址发送。
其次,必须将Postfixconfiguration为使用smtp_generic_maps
。 这将根据/etc/postfix/main.cf
指定的文件自动将内部地址映射到外部地址。如果您希望服务器接收邮件,则还应该使用canonical_maps
。
我使用的configuration是为了强制postfix发送所有用户的所有电子邮件为[email protected]
/etc/postfix/main.cf文件:
smtp_generic_maps = hash:/etc/postfix/generic
在/ etc /后缀/通用:
[email protected] [email protected] [email protected] [email protected] @example.com [email protected] @server-hostname [email protected] @server-hostname.example.com [email protected]
文档位于http://www.postfix.org/ADDRESS_REWRITING_README.html#generic