The Linux Operating System

Download Report

Transcript The Linux Operating System

Tonga Institute of Higher Education
The Linux Operating System
Lecture 7:
Email
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.
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)
–
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.
Like most Linux programs, Sendmail is changed
through configuration files
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 likes to see
First open the file “access” - This is the file that contains all the
domains that will be allowed to use your Sendmail 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 in your domain here and any domains that
might be own your network
Setting up Sendmail
●
●
●
●
You'll also want to open up the file “localhost-names” - This will contain other names
for your computer, so that Sendmail will still
accept mail from these domains.
This file should contain any other names you
have for your computer
Now your sendmail will know who it is good
to accept mail from and who it is not good.
If you haven’t set these up the right way and
you are not receiving mail, you can look
inside “/var/log/maillog” for any error
messages
Setting up Sendmail
●
●
●
The actual sendmail configuration file is in
“sendmail.cf” but it has become so
complicated they made another
configuration file, which you then compile to
make into the “sendmail.cf”
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
But how does anyone else on the Internet know
how to 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. In DNS,
the MX records will look like the following.
In this example, mail.example.com handles mail, but
mail.connect.com will also accept mail if the primary is
down:
example.com. IN
MX
10 mail.example.com
●
example.com.
IN
MX
100 mail.connect.com
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 though
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
You can make one yourself though by creating a file
called “/etc/procmailrc”
This is the file where you can put rules that will
change how mail is delivered
Procmail configuration
●
●
●
●
●
Procmail configuration let's you do almost anything you
can imagine to email, but you have to know the right way
to configure
Once you have the procmailrc file open, you can start
putting rules.
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.
If you left out the 'c', it would instead send all email to
that file
Procmail
Example: If you wanted to delete all email that came
from a certain domain
:0
* ^From.*[email protected]
/dev/null
●
●
●
The first line says a new rule is starting. The next
line checks if the 'From' field is from '[email protected]'
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.
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, it is
not difficult, but can be confusing because there
are no startup scripts in the “rc.d” folder
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.
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.
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
SMTP
●
●
●
●
●
●
You will also hear about SMTP servers if you use computers.
SMTP – Simple Mail Transfer Protocol – is a program that
runs on a server and will send messages
When we set up and turned on Sendmail, the SMTP server
also started.
When you send email from a client computer, you need a
SMTP server to send it through. This is what is responsible
for sending those messages to the rest of the Internet
It operates on port 25. 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
What happens then is that the IMAP or POP
server thinks it is connected to something
that will know how to speak it's language. If
you knew the protocol that IMAP or POP
used, you could get your email this way too.
Local and Remote Email
●
●
●
●
You should be aware of when you are getting email from
remotely and when you are accessing it locally on the server
If you telnet into a server, and use a program like 'pine' or
'mutt' this means that you are accessing the local copy of the
email.
Your email is saved in a file in the “/var/mail” directory under
your username. These programs open up that file and break
it up so that it looks like there are many messages
IMAP and POP3 are services that run on a server that allow
client computers to use different programs (like Microsoft
Outlook) to access email over a network. IMAP and POP will
also open up your mail file, but they are not programs you
use to read email. They are servers that will send your email
to program that asks for it
Updating programs
●
●
●
●
Sendmail, especially, but also IMAP and POP3 have
been vulnerable to many security holes in the past.
This is because they run as root, so if you can
break in through the program, you can have root
access to the system
So one of the first things to do is to update
Sendmail (get the newest from sendmail.org) and
then IMAP as well.
Generally, the installations are pretty easy, but we
might need to change startup scripts.
Summary
●
●
Again, we've condensed a lot of information into a short
sequence of notes. Sendmail, procmail, IMAP and POP are
all powerful programs with many different possible
configurations
For more information about Sendmail:
–
●
More information about Procmail
–
●
http://userpages.umbc.edu/~ian/procmail.html
More info about IMAP
–
●
http://www.sendmail.org/
http://www.imap.org/about/
More info about SMTP
–
http://www2.rad.com/networks/1998/smtp/smtp.htm