Setting up email servers.
Email Email has many aspects that work together to give people almost instant communication from any computer on the internet to any other computer There are three main parts that we will look at: sending email on a server, receiving email on a server and receiving email as a client The simplest is to receive email as a client. You merely put in the name of the server that holds your email and download it.
Cont.. On Linux, you can view your email through many different programs. There are graphical programs like Mozilla, Ximian Evolution and Kmail You can also use programs from the command line like 'pine' and 'mutt'
Email on the Server Getting and reading email is simple on a client, but setting up a server to get and send email requires a little more understanding of how email works There are three parts to have an email server The MTA – Mail Transport Agent (most people use the program called 'sendmail') The LDA – Local Delivery Agent (most people use the program procmail)
Cont… IMAP and POP3 servers – these are two ways to get email from a server. When a client connects to a server to get email, they will use one of these servers
Setting up Sendmail Sendmail normally runs with all RedHat distributions, so you won't need to start any service. Sendmail is a Mail Transport Agent – this means that it is a program which moves mail from one computer to another computer. It is estimated that 80% of all email is handled by Sendmail today. With Sendmail, you can do many things, like block spam, relay mail, have forwarders and configure ways to route mail automatically across networks.
Setting up Sendmail Setting up Sendmail can be an enormous task if you want to do complicated things, but if we just want it to accept email, we can keep it simple. First change into /etc/mail where the sendmail files are saved Sendmail has a different configuration, where you edit files and then compile them into a form that Sendmail accepts.
Cont… First open the file “access” - This is the file that contains all the domains to which the Send mail is allowed to send emails. You’ll also want to make a file called “relay-domains” and put your domain in there. This is to stop people from outside using your server to send spam You need to add your domain here and any domains that might be owned by your network
Setting up Sendmail You'll also want to open up the file “local-host-names” - This will contain other names for your computer, so that Send mail will still accept mail from these domains. This file should contain any other names you have for your computer Now your sendmail will know from whom it can accept mail from and whom it must not.
Setting up Sendmail The actual sendmail configuration file is “sendmail.cf” to which the changes are made, which you then compile to make into the “sendmail.mc” In RedHat, they use this program called “m4” to generate the sendmail.cf file So after we edit the “sendmail.mc” file, we use m4 to change it, like [root@comp root]# m4 sendmail.mc > sendmail.cf
Setting up Sendmail Now that you have the configuration set up for Sendmail, you can restart the service if you want to take the new changes into affect So we use the service command to restart sendmail [root@comp root]# service sendmail restart And you can check to see if it's running by using 'ps -aux' and you'll see an entry that says, “sendmail: accepting connections” This means that it is up and running and people can send email to your server
MX Records MX Records – Mail Exchange records are part of the DNS system for the entire Internet. In order for other computers to know where to send you email, you need to have the correct MX records set up on some Name Server on the internet. They use a numerical priority determines the order in which servers should be used. The server with the lowest priority is the primary.
Local Delivery Agents In most RedHat distributions, Sendmail will get the mail from some server on the Internet and then pass it off to another program for local delivery This means there is another layer of handling before an email will reach your inbox. Procmail is usually the program that is chosen to do the local delivery. The reason that there is another layer is that it is easy to do things to mail after it has come in with procmail. For example, you could sort mail into different folders, delete it if it is spam or make copies of everybody's email
Procmail When a new message comes in, Procmail will start automatically and deliver the mail to the correct folder for the person to read it You can change how mail is delivered through a procmail configuration file. Initially, there is no configuration file for procmail, because it will just give whatever mail comes in to the person who should receive it
Cont… You can make one yourself though by creating a file called “/etc/procmail.rc” This is the file where you can put rules that will change how mail is delivered
Cont… For example, if you want to make a copy of everyone's email so you can read it yourself: :0c /home/mycopy-email The ':0' part says that a new rule is starting. The 'c' says copy all email and the following line says where to copy it.
Procmail Example: If you wanted to delete all email that came from a certain domain :0 * ^From.*bad-person@bad-domain.com /dev/null The first line says a new rule is starting. The next line checks if the 'From' field is from bad-person@bad-domain.com
Cont… The last line says move that message to /dev/null if the email is from that person /dev/null is like the trash bin for linux. If you move something there, it delete's it automatically.
IMAP and POP3 The last part of setting email on the server is to have a way for users to get that email. The most popular way is through to services called IMAP and POP3 IMAP - Internet Message Access Protocol It permits a "client" email program to access remote message stores as if they were local.
Cont… For example, email stored on an IMAP server can be manipulated from a desktop computer at home, a workstation at the office, and a notebook computer while traveling, without the need to transfer messages or files back and forth between these computers.
Turning on IMAP To get IMAP and POP3 working on your server or to get them started, you need to edit a file called “/etc/inetd.conf” This file has a list of all the services that are running and what ports they are connected on.
Cont.. Look down the list until you see the info for port “139” – pop3 and “143” – IMAP. Uncomment those lines and the next time you restart the server, IMAP and pop3 should be started
POP3 The other way to get email is through the POP3 service POP – Post Office Protocol It was the first way to get email from a server. POP3 is the latest version, which has replaced POP2.
Cont… POP is different from IMAP in that everything is downloaded to the client machine. Thus, if you make a change to your mail, it will only be changed on the client machine and not the server You can turn it on using the same procedures from IMAP
Cont… A good way to see if it is running, try [root@comp root]# telnet localhost 25 What this command will do is use the telnet program to connect to port 25 on the computer you are using. You will then be able to see the protocol and server messages coming from the SMTP server
IMAP and POP You can also see how the IMAP and POP servers work by using the same telnet idea IMAP runs on port 143 POP3 runs on port 110 [root@comp root]# telnet localhost 143 [root@comp root]# telnet localhost 110