8

Is there a way to configure Postfix to accept any mail for a domain (catch-all), and then forward that email to the same recipient at a different domain, ignorant of whether the recipient actually exists?

I use Postfix with a MySQL backing for virtual accounts.

8

No this is not directly possible. There is one exception how it can work described in http://www.postfix.org/ADDRESS_REWRITING_README.html#luser_relay

Another crude solution would be to use SQL (substr + concat) to handle this for you in the virtual_alias_maps.

Edit: Oh. There is one last possibility. Use the policy delegation mechanism and return REDIRECT localpart@other-domain.example where you need it and DUNNO if you don't want to rewrite.

Edit 2: Inspired by Squidly (but his solution does not work!) you can setup

virtual_alias_maps = pcre:/etc/postfix/forward_user.pcre, ...

and in that file put

/^(.*)@adomain\.example/    $(1)@other-domain.example

(Watch out for the escaped dot (\.) in the first column.) Personally I would prefer this version.

  • the third solution worked for me. however i had to install the postfix-pcre package (ubuntu 12.10) – scytale Feb 10 '14 at 11:42
1

The pcre table type is unavailable on my system, so I did the following:

  • In /etc/postfix/main.cf:

    virtual_alias_maps = regexp:/etc/postfix/virtual
    
  • In /etc/postfix/virtual:

    /^([^@]*)@olddomain/ $(1)@newdomain
    
1

Not directly possible? I found it very simple and direct with no SQL, regular expressions, or policy mechanisms.

In main.cf:

virtual_alias_domains = alias-destination1.com alias-destination2.com
virtual_alias_maps = hash:/etc/postfix/virtual

In /etc/postfix/virtual:

# I want @true-destination.com to have two incoming aliases
@alias-destination1.com @true-destination.com
@alias-destination2.com @true-destination.com

Sending a test e-mail from the server:

# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 smtp.myserver.com ESMTP Postfix
HELO smtp.myserver.com
250 smtp.myserver.com
MAIL FROM:<somebody@gmail.com>
RCPT TO:<anyuser@alias-destination1.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Message-ID: <4DC3723F.8010907@myserver.com>                                                                                                               
Date: Thu, 05 May 2011 23:59:59 -0400                                                                                                                    
From: Some Body <somebody@gmail.com>                                                                                                                   
To: anyuser@alias-destination1.com                                                                                                                                
Subject: Hello                                                                                                                                           
Just testing.                                                                                                                                            
.

And the actual result in mail.log (I have amavis on port 10025 running):

Apr  6 22:39:43 smtp-a postfix/smtpd[4411]: connect from localhost[127.0.0.1]
Apr  6 22:39:43 smtp-a postfix/smtpd[4411]: 6B47641AF2: client=localhost[127.0.0.1]
Apr  6 22:39:43 smtp-a postfix/cleanup[3706]: 6B47641AF2: message-id=<4DC3723F.8010907@myserver.com>
Apr  6 22:39:43 smtp-a postfix/qmgr[3681]: 6B47641AF2: from=<somebody@gmail.com>, size=1115, nrcpt=1 (queue active)
Apr  6 22:39:43 smtp-a postfix/smtpd[4411]: disconnect from localhost[127.0.0.1]
Apr  6 22:39:43 smtp-a amavis-incoming[2159]: (02159-13) Passed CLEAN {RelayedInternal}, LOCAL [127.0.0.1]:42426 [127.0.0.1] <somebody@gmail.com> -> <anyuser@alias-destination1.com>, Queue-ID: 5C61F41AE5, Message-ID: <4DC3723F.8010907@myserver.com>, mail_id: hUbzH1PtXlzl, Hits: 2.605, size: 394, queued_as: 6B47641AF2, 1224 ms
Apr  6 22:39:43 smtp-a postfix/lmtp[3687]: 5C61F41AE5: to=<anyuser@alias-destination1.com>, relay=127.0.0.1[127.0.0.1]:10024, delay=25, delays=24/0/0/1.2, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 6B47641AF2)
Apr  6 22:39:43 smtp-a postfix/qmgr[3681]: 5C61F41AE5: removed

Key line separated for emphasis:

Apr  6 22:39:43 smtp-a postfix/smtp[3684]: 6B47641AF2: to=<anyuser@true-destination.com>, orig_to=<anyuser@alias-destination1.com>, relay=10.0.0.245[10.0.0.245]:2525, delay=0.03, delays=0.01/0/0/0.02, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 705AA40459)
Apr  6 22:39:43 smtp-a postfix/qmgr[3681]: 6B47641AF2: removed
0

If you use MySQL as the storage end, I believe that you can specify a catch all forward like this:

Table Forwardings

| source       | destination   |
|==============|===============|
| @example.com | @yoursite.com |

If I read the documentation right, it would mean that user1@example.com will now be forwarded to user1@yoursite.com, etc.

I found this in this howtoforge tutorial

-1

Depending on how you setup your Postfix you may be able to use an alias to forward all mail.

edit

Also you can setup a redirect that will do it for you easily.

In /etc/postfix/main.cf add this:

recipient_bcc_maps = pcre:/etc/postfix/forward_bcc.pcre

Then in /etc/postfix/forward_bcc.pcre add this:

/^user@olddomain.com/ user@newdomain.com

This is a bit of a hack but it will work for forwarding specific users from one domain to another.

You also may want to look at this page for how to do some rewriting within Postfix it's self.

  • Can you be more specific? I know I can specify @somedomain.com to forward all mail to a specific address, but I want to know if I can forward to the same recipient. – Abraham Vegh Sep 19 '11 at 16:21
  • in /etc/aliases set it up like this. $username: $username@newdomain.com – Squidly Sep 19 '11 at 17:02
  • @Squidly Your edit is not a regular expression and will not work. You comment about /etc/aliases will not work as the OP has only virtual users. – mailq Sep 19 '11 at 21:35
  • @mailq. That is LIVE on MY server right now. It works perfectly for multiple redirects. Also he did not say these were ONLY virtual users. It was also giving options to look at. – Squidly Sep 20 '11 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.