Pages

Monday, April 23, 2012

Setting up a Relay host with debian6 and exim

The need of the day was to set up a kind of store and forward server, which receives mails from different applications and devices on the network, and sends out using a smart host. 
smart host is microsoft exchange, which requires authentication, and will send out if and only if the sender and authenticated users are same.

This task was achieved by setting up a exim4 SMTP server and rewriting the address.  as follows:

First install package exim4
apt-get install exim4

You have to configure it
dpkg-reconfigure exim4-config

Our need is to receive mail from many clients and sent it using smart host.
screen 1 : Mail sent by smarthost/received via SMTP or fetchmail

I did not understand this but still writing domain part has worked fr me.
screen 2 : Give a mail name (domain part)

This is to notify the server on which interfaces it should be listening for incoming mails.
screen 3 : Write down the interfaces on which the system has to listen separated by semicolons (;)

This is mail receiving destination domains,  and we donot need this
screen 4 : Leave blank

These are the networks on which the server accepts the incoming mails.  Provide all your networks,  also care has to be taken that outsiders should not be able to use these networks.
screen 5 : Add the networks to listen for separated by semicolons

Enter your smart host, which is used for sending out the mail
screen 6 : Put the outgoing mail server address with port ( ip.address.of.server:port )
This option is enabled as the smarthost sends out if and only if authenticated user and sender address are same.
screen 7 : Yes

So put your domain, from where the mail has to go out.
screen 8 : Put your domain name

If you are on a low bandwidth you can minimise DNS querries, otherwise
screen 9 : No

Remaining screens just choose default.  This will include configuration in single file as "yes"

This will complete the setup of the mail server.

Now we have to give the password to authenticate againist the smart host.  This taks is acheived by editing the file /etc/exim4/passwd.client to look as follows
target.mail.server.example:login:password

now edit /etc/exim4/exim4.conf.template
go to line

begin rewrite

and below you can add your configuration

example

*  "someone@someaddress.com Ffs

will change
envelop From, from, sender fields

The flages are important as they do specific functions  as below.

E       rewrite all envelope fields
F       rewrite the envelope From field
T       rewrite the envelope To field
b       rewrite the Bcc: header
c       rewrite the Cc: header
f       rewrite the From: header
h       rewrite all headers
r       rewrite the Reply-To: header
s       rewrite the Sender: header
t       rewrite the To: header

You should be particularly careful about rewriting Sender: headers, and restrict this to special known cases in your own domains.

Also it is possible to write scripts, which do more complex jobs, and use the list from a file.
you can find them from exim documentation at http://www.exim.org/exim-html-3.30/doc/html/spec_34.html

Now restart exim
/etc/init.d/exim4 restart

It is all set to go,

You can verify how redirecting is working by  issuing

/etc/exim4# exim -brw dingo
 sender: someone@someaddress.com
 from: someone@someaddress.com
 to: dingo@someaddress.com
 cc: dingo@someaddress.com
 bcc: dingo@someaddress.com
 reply-to: dingo@someaddress.com
 env-from: someone@someaddress.com
 env-to: dingo@someaddress.com
 
 Now you see which fields are actually rewritten.

Thats all,  Bingo,  your store and forward server is working now .

No comments:

Post a Comment