Advertisment

Linux for Enterprise: Set up an Intranet Mail Server

author-image
PCQ Bureau
New Update

We assume that you have a mail server on the Internet, and that you are setting up a local mail server on the intranet to route local mail. That is, mail to a user on the network will remain local, and will not reach the Internet mail server.

Advertisment

For the purpose of this article, we have used the following settings. 






Intranet Network: 192.168.1.0


IP address of local Email Server running PCQLinux 2004: 192.168.1.4


Hostname of the local Email Server: intranetmail.cmil.com


Internet mail server: mail.cmil.com


Email domain: cmil.com


Gateway (to Internet): 192.168.1.1












Make sure to substitute our settings with yours throughout the article. 

Local mail routing



We will do the set up in such a way that mail destined to non-existent (on the intranet server) accounts, but belonging to the same domain, are sent to the Internet mail server. For example, suppose users Shekhar and Anoop are sitting in the Delhi office on the local intranet network (mentioned above) and Sanjay is sitting in the Mumbai office. Their e-mail addresses are shekhar@cmil.com, anoop@cmil.com and sanjay@cmil.com. While Shekhar and Anoop have user accounts on the intranet e-mail server, Sanjay does not. If Shekhar sends an e-mail to Anoop, it will remain on the local intranet server at 192.168.1.4. But, if he sends an e-mail to sanjay@cmil.com, it is sent to the Internet e-mail server

(ie, mail.cmil.com). 

Postfix, imapd, ClamAV, Spamassassin, Amavis 



These are the names of an SMTP server, POP server, anti-virus, anti-spam and a package that allows the SMTP server to interface with the anti-virus and anti-spam packages, respectively. Traditionally, we have talked about setting up Sendmail for SMTP server, but in this article we set up Postfix which happens to be pretty easy (as you will see below) to configure, even for our complex setup. All these packages are included in PCQLinux 2004. The corresponding RPMs are on the three PCQLinux CDs. So, the easiest way to install these packages is during the PCQLinux installation. 

Advertisment

Set up the prerequisites 



While installing PCQLinux 2004 on the intranet server machine, at the Package Selection screen, select amavisd-new and clamav package under PCQLinux Specials>Security. This will install all the needed packages automatically. 

Create user accounts for email users on your private network on the PCQLinux machine (192.168.1.4). You can create user accounts using the useradd command as:






useradd







Subsequently, you can assign passwords to the user as:





passwd








Alternatively, you can do it graphically through Webmin. For this launch Webmin. Browse to System>User and Groups. Click on Create a new user. For Username, fill in the name of the user account say Edit. Select the option normal password and fill in a password for the account. Optionally, fill in the Real name of the user. For Shell, select /bin/bash from the drop down menu.

Set up Postfix 



Launch Webmin. Click on Servers>Postfix Configuration. Click on General Options. For ‘What domain to use for outbound mail’, select the radio button next to the text field and fill in cmil.com in the text field. For ‘What domains to receive mails for’, fill in cmil.com. Scroll down, and for ‘Local internet domain name’, click on the radio button next to the text field and again type in cmil.com. Click on Save and Apply. 

Advertisment

On the ‘Postfix Configuration’ page, click on ‘Address Rewriting and Masquerading ‘. For Address Masquerading, click on the radio button next to the text field and type in cmil.com in the text field. Click on Save and Apply. 

To set up local mail routing, click on Local delivery icon on the main page. Scroll down and for ‘Optional transport for unknown recipients’, click on the radio button next to the text field and fill in smtp:mail.cmil.com. Here mail.cmil.com is the name of the Internet email server. Using a text editor, open the file named main.cf found in the directory /etc/postfix in a text editor and append the following line to it:






local_recipient_maps =





Note that there is nothing after the equal to (=) sign. Back to Webmin, click on ‘Save and Apply’ on the ‘Local delivery’ page. 


Set up IMAP



If not already installed, install the RPM imap-2002d-3.i386.rpm from PCQLinux CD3. Open a terminal window within X and issue the following command. 






ntsysv







From the listed services, select ipop3. Subsequently, issue the command:






service xinetd restart

Advertisment

Fetching mail from the Internet server 



When people from outside your network e-mail or reply to mail from local users, they will be stored on the Internet e-mail server. This is because we haven’t hosted our local mail server on the Internet, which will need to have a public Internet IP and DNS MX entry. Hence, we need to fetch mail from the Internet e-mail server to the local e-mail server, so that when local users connect to the intranet server using their e-mail clients they get e-mail from the Internet as well. This is done using Fetchmail. If not already installed, install the RPM named fetchmail-6.2.0-8.i386.rpm from PCQLinux 2004 CD 1. 

In Webmin, browse to Servers>Fetchmail Mail Retrieval. Suppose you want to fetch mail for a user named billing. Click on the button labeled ‘...’. This will pop-up a window showing all user accounts. 

Click on the user name (say, Anop). Click on Add Fetchmail Server for user. For ‘Mail server to contact ‘ click on the radio button near the empty text box. Fill in the following details:






Server Name: intranetmail.cmil.com


Mail Server to contact: mail.cmil.com


Remote user: anoop


Remote password: xxxxx


Local user: anoop@cmil.com











The remote user and password are the login and password of the user on the Internet mail server. For Protocol select POP3 or IMAP depending on the one supported by your Internet mail server. Click on create. Similarly, key in details for other email users. 

Advertisment

Fight spam, kill viruses



To set up the anti-spam and anti-virus packages, first open the file named amavisd.conf found in /etc directory. Find the line saying ‘$mydomain = example.com’ and change example.com to cmil.com (the E-Mail domain). Scroll down to the line that 



says





<‘Clam Antivirus-clamd’,





and substitute /var/amavis/clamd with /var/run/clamav/clamd.sock in the line below it. Also remove the preceding # (hash) from each line. When done, the section should look as follows.





<‘Clam Antivirus-clamd’,


\&ask_daemon, <“CONTSCAN {}\n”, ‘/var/run/clamav/clamd.sock’>,


qr/\bOK$/, qr/\bFOUND$/,


qr/^.*?: (?!Infected Archive)(.*) FOUND$/ >,





Next, open the file master.cf found in the directory /etc/postfix in a text editor. Find the line which says:





smtp inet n - n - - smtpd





And append ‘-o content_filter=smtp-amavis:<127.0.0.1>:10024’ to this line, so that it looks as follows:





smtp inet n - n - - smtpd -o content_filter=smtp-amavis:<127.0.0.1>:10024





Append the following lines to the end of the file:





smtp-amavis unix - - n - 2 smtp


127.0.0.1:10025 inet n - n - - smtpd





Save the file.























Get, set, go



With the configuration in place, we are ready to deploy our E-Mail system. Start Postfix server as:






service postfix start


Start Amavisd As:


service amavisd start


Launch Spamassassin as:


service spamassassin start


Launch Clam Antivirus as:


service clamd start














To update Clam with the latest virus definitions, issue the following command:






freshclam








Point the e-mail clients on the network machines to the IP address of the Linux machine or read on to Web-based e-mail client. 

Webmail



PCQLinux 2004 ships with a PHP-based Webmail system called SquirrelMail. To install it either select Server>Mail Server>Details>squirrelmail during installation else install the RPM named squirrelmail-1.4.0-1.noarch.rpm found on PCQLinux 2004 CD3 . Intsall the RPM as:





rpm -ivh squirrelmail-1.4.0-1.noarch.rpm





It may complain of certain required packages like PHP and httpd (Apache). All these packages will be available on one of the 3 PCQLinux CDs. 



Advertisment

To run SquirrelMail you must run IMAP server on the PCQLinux machine. For this issue:






ntsysv





and select ‘imap’ from the list of services. Select OK and subseuqently issue the following commands:





service xinetd restart


service httpd start 












The second command starts the Apache web server required to access the web based email. Henceforth, you can access the Webmail by keying in the following URL in the web browser:





http:///webmail







Login using the Email login and password (same as the login credentials for the linux user accounts created in the section Install/Setup the Prerequisites). And you will be welcomed by a full-fledged and neat web mail system. 


At the end, you should have a robust Email system with PCQLinux 2004, up and running. Spam and virus infected mails will bounce back to the sender.

Shekhar Govindarajan

Advertisment