Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to send all local mail to a single external e-mail, using Google's SMTP servers.

Using Google's SMTP servers work, as I am able to send mail to external addresses work using mail from mailutils.

The redirection of local mail to the external e-mail does not work. When sending a mail to root from my account test using:

echo "Body" | mail -s "Test Postfix To Root" root
  • I never recieve the message
  • Nothing new turns up in /var/log/mail.err
  • This turns up in /var/log/mail.log
Sep  4 18:48:06 desktop1204test postfix/pickup[5535]: C9326EE26: uid=1000 from=
Sep  4 18:48:06 desktop1204test postfix/cleanup[5702]: C9326EE26: message-id=
Sep  4 18:48:06 desktop1204test postfix/qmgr[5534]: C9326EE26: from=, size=401, nrcpt=1 (queue active)
Sep  4 18:48:06 desktop1204test postfix/local[5704]: C9326EE26: to=, orig_to=, relay=local, delay=0.03, delays=0.02/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Sep  4 18:48:06 desktop1204test postfix/qmgr[5534]: C9326EE26: removed

My /etc/postfix/main.cf:

inet_interfaces = loopback-only
mynetworks = loopback-only
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
virtual_alias_domains = localhost.localdomain
virtual_alias_maps = hash:/etc/postfix/virtual
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

My etc/aliases:

# See man 5 aliases for format
postmaster:    root

My /etc/postfix/virtual:

@localhost.localdomain        someone@somewhere.com

How can I get it working? I don't want any local mail to arrive locally, they should all go to someone@somewhere.com.


I tried the solution suggested in a comment below: put *: someone@somewhere.com in /etc/aliases. But did not work:

test@desktop1204test:~$ sudo newaliases
test@desktop1204test:~$ cat /etc/aliases
# See man 5 aliases for format
postmaster:    root
*: someone@somewhere.com
test@desktop1204test:~$ sudo newaliases 
test@desktop1204test:~$ sudo service postfix restart
 * Stopping Postfix Mail Transport Agent postfix                                                     [ OK ] 
 * Starting Postfix Mail Transport Agent postfix                                                     [ OK ] 
test@desktop1204test:~$ echo "Body" | mail -s "Test Postfix To Root $(date)" root
test@desktop1204test:~$ tail /var/log/mail.err 
test@desktop1204test:~$ tail /var/log/mail.log 
......
Sep  4 22:46:12 desktop1204test postfix/master[7224]: daemon started -- version 2.9.6, configuration /etc/postfix
Sep  4 22:46:23 desktop1204test postfix/pickup[7227]: 859AFF6A8: uid=1000 from=<test>
Sep  4 22:46:23 desktop1204test postfix/cleanup[7235]: 859AFF6A8: message-id=<20130904204623.859AFF6A8@desktop1204test.localdomain>
Sep  4 22:46:23 desktop1204test postfix/qmgr[7228]: 859AFF6A8: from=<test@desktop1204test.localdomain>, size=431, nrcpt=1 (queue active)
Sep  4 22:46:23 desktop1204test postfix/local[7237]: 859AFF6A8: to=<root@desktop1204test.localdomain>, orig_to=<root@desktop1204test>, relay=local, delay=0.02, delays=0.02/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Sep  4 22:46:23 desktop1204test postfix/qmgr[7228]: 859AFF6A8: removed
test@desktop1204test:~$
share|improve this question
    
Related: unix.stackexchange.com/questions/5771/… –  slm Sep 4 '13 at 17:36
    
"Can I change root's email address or forward all mail to an external address?" suggested in the box on top did not help me. It suggests creating files in each users home directory. I want a catch all which works even if the user does not have a home directory. I'll check the other suggestions here in the comments. Thanks for trying to help me! –  Deleted Sep 4 '13 at 20:11
    
@sim: That suggests using esmtp, which I don't want to use. But thanks for trying to help! –  Deleted Sep 4 '13 at 20:13
    
Look at the possible duplicate one. That showed how to use the /etc/aliases file to setup forwarding. –  slm Sep 4 '13 at 20:16
    
Put in /etc/aliases this: *: someone@somewhere.com : unix.stackexchange.com/questions/65013/… –  slm Sep 4 '13 at 20:21

1 Answer 1

(This was answered on AskUbuntu by Pasi Suominen, a big thanks to him!)

This can be accomplished via virtual regexp (/etc/postfix/virtual-regexp)

/.+@.+/ someone@somewhere.com

then in main.cf:

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

and the mapfile:

postmap /etc/postfix/virtual-regexp

That should do the trick for all local mails (otherwise you must specify all addresses on virtual)

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.