Ubuntu – Configure Exim to forward email

emailemail-servereximUbuntu

I have an Ubuntu 10.04 VPS set up to manage sub.example.com and I've configured Exim to send email using this tutorial from the Linode Library. That's working, but in addition to sending email I realized I need a single non-root email address (admin@sub.example.com) to forward to me (me@gmail.com).

I've read the Exim documentation on this [1] and I don't really get what I'm supposed to do (it seems to expect that readers already know what files to change and what certain directives do). There's also a similar question here from '09 and I can't tell which (if any) of the solutions there would apply to my case or what files need to be modified with the suggested lines.

TBH, I'd be just as happy if there is a very simple way to do this without Exim that wouldn't conflict with sending email through Exim the way I already have it set up. I have already tried modifying /etc/aliases to no avail.

You can probably tell I'm pretty new to configuring MTAs… thanks in advance.

[1] Which I apparently can't link to, since this is my first post on ServerFault. I believe the relevant section is Chapter 22 – The redirect router.

Best Answer

In the explanation that follows, I am assuming that you followed the instructions in the URL you mentioned and you have selected "internet server". I also assume that "localhost" is one of the valid domain names that your exim is configured to recognize as a local domain.

First, the format of what you put in /etc/aliases should have been:

admin: me@gmail.com

You don't need to run newaliases on an exim system, it's just provided as a compatibility layer for applications expecting a more "sendmail-like" environment. Exim directly scans the contents of the /etc/aliases file the first time it reads it and caches results, remembering it for subsequent lookups if there are any. It doesn't actually use the /etc/aliases.db file like sendmail does.

When you edit /etc/aliases, you can test how an address will be handled from the commandline. In this first example, my system is not configured to handle the admin alias. It complains that it doesn't know how to handle this address by describing it as undeliverable:

[todd@tlyons /etc/exim4]$ grep admin /etc/aliases
[todd@tlyons /etc/exim4]$ exim -bt admin@localhost
R: system_aliases for admin@localhost
admin@localhost is undeliverable

In the second example, my system is properly configured to handle the admin alias. Explanation follows the example:

[todd@tlyons /etc/exim4]$ grep admin /etc/aliases
admin: me@gmail.com
[todd@tlyons /etc/exim4]$ exim -bt admin@localhost
R: system_aliases for admin@localhost
R: dnslookup for me@gmail.com
me@gmail.com
    <-- admin@localhost
  router = dnslookup, transport = remote_smtp
  host gmail-smtp-in-v4v6.l.google.com [2001:4860:b007::1a] MX=5
  host gmail-smtp-in.l.google.com      [173.194.79.27]      MX=5
  host gmail-smtp-in-v4v6.l.google.com [209.85.225.27]      MX=5
  host alt2.gmail-smtp-in.l.google.com [74.125.45.27]       MX=20
  host alt3.gmail-smtp-in.l.google.com [173.194.66.27]      MX=30
  host alt4.gmail-smtp-in.l.google.com [173.194.65.27]      MX=40

The first R: line is a debugging output line that says it was processing the email address with the "system_aliases" router. It doesn't come out and say it directly, but it did find "admin" in the system_aliases router and "expanded" that to "me@gmail.com". Once exim expands an address to something else (or multiple somethings), it reruns each address through the routers, looking for a match. In the example above, it ran the me@gmail.com address through the routers and the "dnslookup" router matched. That means it determined it needed to use SMTP to send it out to a remote mail server. Part of that is looking up the MX records of gmail.com, which it did and displayed for you to see how it would try to deliver that mail.

So to answer your original question, it's likely that you just entered the data in your /etc/aliases incorrectly. The left hand side is just the local part (ie the "user" in user@domain.com), followed by a colon (:), followed by spaces or tabs, followed by the email address (or email addresses joined by commas) to deliver it to. You cannot put the complete email address as the left hand side (before the colon).