postfix 2.9.6.1 forward all mail to an external mail address

好久不见. 提交于 2019-12-04 18:52:41

Finally found the answer.

Listing here for posterity.

Add the folowing line to the end of your main.cf file

vi /etc/postfix/main.cf 

virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp

Create a file which lists the mail address you want all mails to be sent to

vi /etc/postfix/virtual-regexp

Add the following:

/.+@.+/ forwardingmailaddress@gmail.com

add it to postmap

postmap /etc/postfix/virtual-regexp

you will need to add a virtual file.

touch /etc/postfix/virtual

now add it to postmap

postmap /etc/postfix/virtual

I had similar trouble forwarding to my Gmail account. I had one host running postfix, forwarding multiple virtual domains. Even though I was pretty sure that I had set the config files (/etc/postfix/virtual, /etc/postifx/main.cf) properly, the messages would sometimes arrive, but sometimes I'd get bounce messages.

To get it working, I also had to:

  1. Send test messages from some other account. Gmail appears to discard messages that come to it having been sent from the same mailbox/address because it thinks there's a mail loop. Send your test message from some other account, or even use the following from the host where you're running postfix.

    echo "test to foo@example.com" | sendmail foo@example.com
    
  2. Add a SPF record for the host that's forwarding the mail (running postfix). A SPF record indicates to other computers that the domain owner says that the relaying host is allowed to send mail for that domain. The basics of SPF are at OpenSPF: http://www.openspf.org/Introduction. Google has a good writeup at https://support.google.com/a/answer/33786  

    TL;DR Create a TXT record containing this text: v=spf1 mx include:_spf.google.com ~all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!