2

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.

2 Answers 2

3

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

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

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

Expanded step 2

Using postfix pcre is only one way to achieve this among many others . According to this tutorial by garisson :

  1. Create a local user mylocaluser and it's mailbox or maildir
  2. Create a file named aliases-pcre with content :

    /@example\\.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
    
  3. Restart postfix

Now, all mail destinated to *@example.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.


However, 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 = example.com
mydestination = localhost

File /etc/postfix/aliases-pcre

/@example\.com$/ somelocaluser
8
  • Can you expand on how to do step 2, or point me to some documentation for it? Jul 31, 2012 at 18:53
  • No, it's still not liking the "localpart" - I send emails to [email protected] and it bounces them with "unknown user paul.tomblin". Email to "[email protected]" gets delivered to me, so I know the mydestination part is working. Jul 31, 2012 at 22:39
  • I tested my PCRE file using postmap -qand it does match [email protected] but not [email protected], but I suspect that the domain might be already trimmed off by the time local(8) gets the address. Jul 31, 2012 at 22:50
  • May i ask you he content of the pcre file?
    – user130370
    Jul 31, 2012 at 22:52
  • Also, what happens exactly when email "Email to [email protected] 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?
    – user130370
    Jul 31, 2012 at 22:54
2

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 = example.com
    virtual_alias_maps = regexp:/etc/postfix/virtual_alias
    
  2. In /etc/postfix/virtual_alias

    /@example\.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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .