3

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:~$
Deleted
  • 409
  • Related: http://unix.stackexchange.com/questions/5771/simplest-way-of-forwarding-all-mail-from-server – slm Sep 04 '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 04 '13 at 20:11
  • @sim: That suggests using esmtp, which I don't want to use. But thanks for trying to help! – Deleted Sep 04 '13 at 20:13
  • Look at the possible duplicate one. That showed how to use the /etc/aliases file to setup forwarding. – slm Sep 04 '13 at 20:16
  • Put in /etc/aliases this: *: someone@somewhere.com : http://unix.stackexchange.com/questions/65013/understanding-etc-aliases-and-what-it-does – slm Sep 04 '13 at 20:21
  • @slm: I tried your suggestion now. It did not help. :-( It is thus NOT a duplicate. – Deleted Sep 04 '13 at 20:57
  • Did you try using the newaliases command after adding the entry? – slm Sep 04 '13 at 21:07
  • @slm Postfix doesn't support wildcards in aliases out of the box. – Gilles 'SO- stop being evil' Sep 04 '13 at 21:40
  • @Gilles - do you know off hand if it supports @localhost: ... or is it any form of a wildcard? – slm Sep 04 '13 at 22:06
  • @Gilles - I think ken has left, he's deleted his account and seemed pretty steamed. I've nominated to reopen. – slm Sep 04 '13 at 22:07
  • @slm I think you can arrange to load a PCRE module and apply regexps to aliases but I don't know the details, and this might not be the easiest way. Offhand I'd investigate /etc/postfix/virtual first. – Gilles 'SO- stop being evil' Sep 04 '13 at 22:13
  • @Gilles - I found this solution, http://serverfault.com/questions/23717/postfix-how-do-you-redirect-all-emails-to-one-user-eg-example-com-userex. It requires that you change these lines in your main.cf: luser_relay = user@example.com. Also this line needs to have no values assigned: local_recipient_maps = – slm Sep 04 '13 at 22:44
  • I'm actually here. Even though I think the site is going down the drains. I had an account earlier I renamed to Deleted as I actually wanted to delete it. Now it seems my new account and that one has got mixed up... Hm.. Anyway, if you would have actually read what I wrote @slm (see above) you would have seen that I did test that solution. – Deleted Sep 05 '13 at 20:05
  • I got an answer to the same question at AskUbuntu. I'm posting it here as an answer. – Deleted Sep 05 '13 at 20:10
  • @Deleted - OK. I know nothing about the accounts, sorry about that frustration. Also sorry we quickly dismissed this as a duplicate. I take responsibility for that one. I do not have a usable postfix install so was only trying to help. In looking through your original Q it seemed like it was a dup., and I have pretty extensive experience with sendmail, so the Q on the surface appeared to be one. I'm glad you were able to get a solution to your problem. That's most everyone's goal here. – slm Sep 05 '13 at 20:17
  • @Deleted - I try very hard to help people as best as I can, I did read through your Q and did not see a reference to the luser_relay... suggestion. I still don't see it in your Q. Regardless, you seemed to get extremely frustrated with how your Q was handled, and in the future all I can suggest is that there is a process to these sites and if you go in with understanding that, Q's might get labeled as dups., or off topic, but if they are worthy Q's to the site they are posted on, they will get re-opened and answered as they are better understood by the community. – slm Sep 05 '13 at 20:24
  • @Deleted - All of us here are human too and are learning too. So in this case you have educated all of us on how to do this with Postfix, so I thank you for coming back and closing the loop on this. I hope we (I specifically) haven't turned you off to the U&L site because that would be the one thing I've tried very hard never to do, I enjoy frequenting this site, and would never want to have turned someone away intentionally or otherwise from the it. I think if you stay around you'll find it to be one of the more friendly SE sites, just my $0.02! – slm Sep 05 '13 at 20:28

2 Answers2

4

(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)

Deleted
  • 409
0

To use one email forwarding for all root mail:
echo "your_email_address" >> /etc/aliases && newaliases and test with:
echo "body" | mail -s "subject" root

Now all apps mailing to root will go to your email. More info here:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04#step-3-testing-the-smtp-server

alchemy
  • 597