Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Linux server which uses Postfix for email. Its on a dynamic ip so I use the "relayhost" parameter to send outgoing mail through an ssh tunnel to another server on a static ip and from there it goes out to the real world. That's been working fine since about 1998 or so.

I'm currently developing some software for a client, and it sends email to various people in that client's organization based on information in a database. For my initial testing, I created fake people who all had email addresses like ptomblin+client1@{mydomain}.com, which worked fine and sent all the email to me. But now I'm working with a live database, and all the email addresses are for real people in the client's organization. I don't particularly want to send email to those people telling them that the system access they requested has been provisioned, so I'd like a way to redirect all email to that client's domain to either my email address or to a file.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If I understand correctly, you want all the mail destinated to mydomain.com be delivered to your mail address or a file, instead of being forwarded to the server specified in relayhost :

step 1 : Add mydomain.com to mydestination in main.cf so that mail destinated to mydomain.com is delivered locally .

step 2 : Setup a catchall for mydomain.com and send all email to your mail address or a file. You can for example use postfix pcre to achieve this.

Edit : Expanded step 2

Using postfix pcre is only one way to achieve this among many others . According to http://cdfx.penguins-on-hudson.com/2007/08/29/multiple-recipient-delimiters-in-postfix/ :

a/ Create a local user mylocaluser and it's mailbox or maildir

b/ Create a file named aliases-pcre with content : /@mydomain\.com$/ mylocaluser

add the following lines to main.cf (if main.cf is in /etc/postfix): alias_database = hash:/etc/postfix/aliases alias_maps = hash:/etc/postfix/aliases, pcre:/etc/postfix/aliases-pcre

c/ Restart postfix

Now, all mail destinated to *@mydomain.com should go to mylocaluser mailbox/maildir.

Again, this is just an example. You can use any other method that best fits your needs. I tend to use pcre a lot because it allows regexp that are a bit more complex.

Edit number 2 :

The above would not work as you need virtual domain.

Here's a minimal sample configuration :

(main.cf)
alias_database = hash:/etc/aliases
local_recipient_maps = 
relayhost = myotherserver.example.com
virtual_alias_maps = pcre:/etc/postfix/aliases-pcre
virtual_alias_domains = mydomain.com
mydestination = localhost

(/etc/postfix/aliases-pcre)

/@mydomain\.com$/ somelocaluser
share|improve this answer
    
Can you expand on how to do step 2, or point me to some documentation for it? –  Paul Tomblin Jul 31 '12 at 18:53
    
No, it's still not liking the "localpart" - I send emails to paul.tomblin@mydomain.com and it bounces them with "unknown user paul.tomblin". Email to "ptomblin@mydomain.com" gets delivered to me, so I know the mydestination part is working. –  Paul Tomblin Jul 31 '12 at 22:39
    
I tested my PCRE file using postmap -qand it does match paul.tomblin@mydomain.com but not paul.tomblin@gmail.com, but I suspect that the domain might be already trimmed off by the time local(8) gets the address. –  Paul Tomblin Jul 31 '12 at 22:50
    
May i ask you he content of the pcre file? –  coincoin Jul 31 '12 at 22:52
    
Also, what happens exactly when email "Email to ptomblin@mydomain.com gets delivered to me" : Can you read the mail in your usual mail client or it get delivred on h postfix srver to user ptomblin? –  coincoin Jul 31 '12 at 22:54

Ok, Eric got me close to the right path, but not quite there. This is what I did:

  1. In /etc/postfix/main.cf:

    virtual_alias_domains = clientdomain.com

    virtual_alias_maps = regexp:/etc/postfix/virtual_alias

  2. In /etc/postfix/virtual_alias

    /@clientdomain.com/ ptomblin

One postfix reload later and I was away to the races. (By the way, you don't need to do postmap on regular expression files, only hashs)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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