This site is now 100% read-only, and retired.

Setting up mail forwarding

Posted by Steve on Mon 27 Dec 2004 at 17:31

Many systems aren't supposed to run as real mail servers, instead they should merely forward mail to a real server. In a home setting this might mean forwarding mail to your ISP. In a work setting you might have a single mailserver which is allowed by your firewall to make outgoing SMTP connections, whilst all other machines are denied this, so you want to have all your linux/unix servers relay mail via your main server. Here we'll look at how different mail servers can be setup to forward mail for you.

I have a mailserver I run which will relay, or deliver, mail for a bunch of domains. This is supposed to be used by all the servers I have in the network.

This is a simple thing to setup, if you're only running one type of mail server. If you're not then you might find these notes useful.


exim is the default mail server installed on Debian installations, and it's configured by the file /etc/exim/exim.conf.

To make exim deliver mail to a different host you need to make two changes:

  • Tell the system what it's domain name is
  • Tell the system where to pass it's mail onto

The first is very simple, look through the configuration file /etc/exim/exim.conf and find set the domain name by changing the value for qualify_domain:

# Specify the domain you want to be added to all unqualified addresses
# here. Unqualified addresses are accepted only from local callers by
# default. See the receiver_unqualified_{hosts,nets} options if you want
# to permit unqualified addresses from remote sources. If this option is
# not set, the primary_hostname value is used for qualification.

qualify_domain =

To tell the system that you want to pass all mail to another host you need to tell it that it's not local - so that nothing ever gets delivered locally:

local_domains =

Now we need to tell it where it should send its mail to. Scroll down towards the bottom of your exim configuration file and you should see something called the 'Routers Configuration'

At the top of this section add the following:

# Remote addresses are those with a domain that does not match any item
# in the "local_domains" setting above.

# Send all mail to a smarthost

  driver = domainlist
  transport = remote_smtp
  route_list = "* bydns_a"


This tells exim that it should forward all mail to the server, so you'll need to change the hostname to point to your mail server.

Once you're done making changes you can run the following command to restart your mailserver:

/etc/init.d/exim restart

Once that's done test that you can send mail out properly.


Sendmail is probably the most common mailserver installed on typical Unix machines, it comes with both SCO and Sun's Unix platforms amongst others.

You will need to find the configuration file wherever it is located, and then edit it.

If you're running one of the following platforms this is where you might find it:

SuSE Linix     - /etc/
SCO Openserver - /usr/lib/
SunOS          - /etc/mail/

Again there are the same two changes to make, firstly setup the domain name that you're sending mail from, and secondly tell sendmail where to relay its mail to.

Sendmail can be a little cryptic to configure if you're not used to it, so the following are samples of what you need to include:

# my official domain name

# "Smart" relay host (may be null)

Here we've set two settings "Dj" to tell the system that all mail should be sent from the domain, and that the mail should be sent via the server at

Restart the server however you usually do so, and all should be working.


Qmail is very straightforward, all the main server settings are stored in the directory /var/qmail.

We will need to change two files:

  • /var/qmail/defaultdomain
    • This contains the domain name that should be used for all outgoing mail.
  • /var/qmail/smtproutes
    • This tells Qmail what servers to send to

The first one can be changed to have a single line containing the domain name mail should appear to have been sent from.

The second one should be changed to read as follows:

This tells qmail to forward all mail to the SMTP server with the hostname which you will need to supply.

Once these two changes have been made you can restart qmail and test that everything works properly.



Posted by Anonymous (127.0.xx.xx) on Mon 27 Dec 2004 at 18:39
exim can be trivially reconfigured using /sbin/eximconfig in Woody and dpkg-reconfigure exim4-config in Sarge, which is much easier than hacking config files and makes package upgrades easier.

[ Parent ]

Sure it can
Posted by Steve (127.0.xx.xx) on Mon 27 Dec 2004 at 18:41
[ View Weblogs ]

If you're running a Woody/Sarge system that works well. This was more taking notes when I was moving non-Debian systems to relay through a central server.

For Debian systems eximconfig works well, choosing "Satellite System" will give you an almost complete setup.


[ Parent ]

Posted by Anonymous (62.209.xx.xx) on Mon 3 Jan 2005 at 22:40
Nice guide, but the hardest part seems to be to add username and password for your ISP mailserver. Is there a reason none (well, at least exim4 and postfix last I checked) do not ask for this when you use dpkg-reconfigure and choose smarthost?

[ Parent ]

Re: Password?
Posted by Anonymous (130.234.xx.xx) on Wed 15 Jun 2005 at 11:48
I think you don't understand completely how satellite system works.
You don't need username/password on your ISP's mail server to send mail, since you use their server to relay the mail sent from your machine.
Your ISP should automatically allow relay from its own domain, but not from the world(open proxy problem).

[ Parent ]

Re: Password?
Posted by Anonymous (59.57.xx.xx) on Fri 22 Jul 2005 at 03:34
I have to forward my mail to my mail-service-provider which requires password and username.

How do you configure that in exim?

[ Parent ]

Re: Password?
Posted by Anonymous (193.217.xx.xx) on Thu 15 Mar 2007 at 20:38
In Norway, the ISP Tele2 require you to use username and password of their mailhost ( for sending email to anybody, when You are within that ISP's network. In other words: I GOT to register with credentials to be allowed to send email through my ISP's mailserver. Spammers have forced that ISP to block outgoing port 25 to all other mailhosts.

[ Parent ]

Re: Setting up mail forwarding - Testing
Posted by Anonymous (216.203.xx.xx) on Fri 17 Mar 2006 at 14:08
How can I make quick test of the settings I just entered? What is the simplest sendmail command to send an email through the server?

[ Parent ]

Re: Setting up mail forwarding - Testing
Posted by Steve (212.20.xx.xx) on Fri 17 Mar 2006 at 14:11
[ View Weblogs ]

Personally I'd usually use "telnet host 25". But in terms of commands you should be able to run:

/usr/sbin/sendmail -t


/usr/lib/sendmail -t

Type in your message:

Subject: test


The '.' on a line of its own will finish the message.


[ Parent ]

Re: Setting up mail forwarding - Testing
Posted by suspended user aikishugyo (133.243.xx.xx) on Fri 11 May 2007 at 03:35

Or try:

$ echo "test message text" | mail -s "test subject" adressee

[ Parent ]