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.
EximSendmailexim 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 = steve.org.ukTo 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 smarthost: driver = domainlist transport = remote_smtp route_list = "* smtp.blueyonder.co.uk bydns_a" endThis tells exim that it should forward all mail to the server smtp.blueyonder.co.uk, 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 restartOnce that's done test that you can send mail out properly.
QmailSendmail 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 sendmail.cf 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/sendmail.cf SCO Openserver - /usr/lib/sendmail.cf SunOS - /etc/mail/sendmail.cfAgain 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 Djsteve.org.uk # # "Smart" relay host (may be null) DSsmtp.company.comHere we've set two settings "Dj" to tell the system that all mail should be sent from the domain steve.org.uk, and that the mail should be sent via the server at smtp.company.com.
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:
:smtp.company.comThis tells qmail to forward all mail to the SMTP server with the hostname smtp.company.com which you will need to supply.
Once these two changes have been made you can restart qmail and test that everything works properly.
Fully Hosted AntiSpam & AntiVirus
Fully managed SPAM & Virus filtering of your incoming Email.
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | 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.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
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 | Reply to this comment ]
How do you configure that in exim?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | 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
Or
/usr/lib/sendmail -t
Type in your message:
To: blah@foo.com From: test@example.com Subject: test test .
The '.' on a line of its own will finish the message.
[ Parent | Reply to this comment ]
Or try:
$ echo "test message text" | mail -s "test subject" adressee
[ Parent | Reply to this comment ]
Fully Hosted AntiSpam & AntiVirus
Fully managed SPAM & Virus filtering of your incoming Email.