1

I'm trying to setup postfix on a Linux machine (Debian 8 with Postfix 2.11). But I have some troubles getting /etc/aliases to work correctly.

The setup is as follows: A MS Exchange server is the actual mail server - it recieves mails and sends mails, and it is in the same local network as the Linux machine. Postfix on the Linux machine does use this Exchange machine as a relayhost to send mails. This works, so for example mail external@gmail.com arrives.

Now on the Exchange there exists a mail address that is forwarded to the Linux machine. In /etc/aliases I have an alias for this that is a pipe to a program, because the mails going to this address contain some code that should be parsed by the program.

In order to make this work, I have to alter the mydestination setting in main.cf. But as soon as I do so, Postfix stops relaying mails when their alias of /etc/aliases is used. Only typing the long name works. This is my configuration (I started from zero):

# main.cf
# our internet domain name (the thing after the "@")
mydomain = example.com

# this is the critical setting
mydestination = linuxmachine, 192.168.1.200, $mydomain

# IP of Exchange
relayhost = 192.168.1.100

# so that addresses look correct
masquerade_domains = $mydomain

# in order to make the pipe programm work with correct permission
default_privs = myuser

With this configuration the piping of incoming mail works, but sending mail to an alias does not work:

# /etc/alias
# none of the entries are actual users on the linux machine!

#works when mail to parser@example.com comes from external through Exchange to Linux
parser: |/home/user/programname 

# command "mail external" does not work! It sends to external@linuxmachine"
external: externalmail@gmail.com 

If I comment out the line mydestination in main.cf then mail external sends a mail to externalmail@gmail.com (which arrives), but incoming mail to parser@example.com is not send through the pipe. So, just the other way round.

What do I have to enter in main.cf or /etc/aliases to be able to send mails from my Linux machine using short names and at the same time be able to receive mail to a pipe? All I want is that a special address is parsed on the linux machine and that linux users are able to send mails to selected addresses using short names as a "luxory" (instead of having to type full email addresses).

Update: postconf -n output:

config_directory = /etc/postfix
default_privs = myuser
masquerade_domains = $mydomain
mydestination = linuxmachine, 192.168.1.200, $mydomain
mydomain = example.com
relayhost = 192.168.1.100

Update 2: Output from /var/log/mail.info when doing mail external (mail to alias) with mydestination set like above:

Jun 19 10:45:27 linuxmachine postfix/smtp[26425]: 6DFE02003AD: to=<external@linuxmachine.example.com>, orig_to=<external>, relay=192.168.1.100[192.168.1.100]:25, delay=0.24, delays=0/0/0/0.24, dsn=2.6.0, status=sent (250 2.6.0 <20150619084527.6DFE02003AD@linuxmachine.example.com> [InternalId=162319] Queued mail for delivery)

Update 3, after changing mydestination according to the proposed answer, the mail.info log shows the following line when doing mail external:

Jun 19 16:07:31 linuxmachine postfix/smtp[2299]: B562720039C: to=<externalmail@gmail.com>, orig_to=<external>, relay=192.168.1.100[192.168.1.100]:25, delay=2.6, delays=0/0/0/2.5, dsn=2.6.0, status=sent (250 2.6.0 <20150619140728.B359620039E@linuxmachine.example.com> [InternalId=162971] Queued mail for delivery)
  • Can you post the output of postconf -n? Also, can you provide maillog when postfix fail to send to external@gmail.com? – masegaloeh Jun 18 '15 at 16:38
  • @masegaloeh I added postconf -n (with mydestination set). Will add log later. – Foo Bar Jun 19 '15 at 8:42
  • @masegaloeh Added the log – Foo Bar Jun 19 '15 at 8:49
3

The obvious solution is put $myhostname or linuxmachine.example.com in mydestination parameter.

explanation

Before the config modification, here the background event after you send email via mail external

  • Postfix receives email via pickup service.
  • Because the recipient doesn't have domain parts and (by default) parameter append_at_myorigin has value yes, then postfix will rewrite recipient address to external@linuxmachine.example.com (you can see it in mail.log above)
  • By default, parameter mydestination has value $myhostname or linuxmachine.example.com, so postfix apply aliasing map in /etc/aliases.
  • Postfix aliased external@linuxmachine.example.com to external@gmail.com and then send it to gmail host

Now after config modification, this is what happens

  • Postfix receives email via pickup service.
  • Because the recipient doesn't have domain parts and (by default) parameter append_at_myorigin has value yes, then postfix will rewrite recipient address to external@linuxmachine.example.com (you can see it in mail.log above)
  • Now mydestination doesn't contain $myhostname or linuxmachine.example.com, so postfix won't apply aliasing in /etc/aliases
  • I now see to=<external@gmail.com>, orig_to=<external> in mail.info, but the mail still does not arrive in the external inbox, however. I tested it with several external mail addresses from different e-mail providers (I run newaliases each time, of course). – Foo Bar Jun 19 '15 at 10:50
  • When I post a mail to me@example.com via alias internal: me@example.com the mail correctly arrives in the Exchange inbox. But If I then look at the mail header, it has: To: <internal@example.com instead of me@example.com. I assume this is the problem why it does not arrive at external servers (Envelope and Mail Headers differ). How do I change this? – Foo Bar Jun 19 '15 at 11:03
  • Can you update the question with log after you modified mydestination? – masegaloeh Jun 19 '15 at 13:56
  • Updated the question with the mail.info message after changing mydestination and doing mail external. – Foo Bar Jun 19 '15 at 14:11
  • Well, mail.log said that postfix successfully relay email to exchange. Please also checks exchange log. – masegaloeh Jun 19 '15 at 14:23

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.