Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Absolute BSD - The Ultimate Guide To FreeBSD (2002).pdf
Скачиваний:
25
Добавлен:
17.08.2013
Размер:
8.15 Mб
Скачать

Chapter 14: Email Services

One of the basic tasks of an Internet server is to relay and receive email. FreeBSD is a quite powerful mail server, and can handle millions of emails a day. This chapter discusses how to handle email flow in the server−to−server case, the client−to−server case, and the server−to−client case. When a server communicates with a server, or a client sends mail to a server, it uses the standard SMTP email protocol. When a client downloads its mail from a server, it uses the POP3 protocol.

Email Overview

Most email is generated by a user at a desktop computer. This is most often a Windows PC or a Mac with Outlook, Eudora, Netscape, or one of their cousins, but you can send mail with almost any operating system. My preferred FreeBSD client is Mutt (/usr/ports/mail/mutt).

The client sends the email to an email server. Almost every company or ISP has at least one dedicated email system. The email server performs some basic sanity−checking on the email sent by the client, and it then tries to find a server that claims responsibility for this message (see "Finding the Correct Mail Host" later in the chapter). The email server transmits the email message to another mail server.

When the recipient checks his email, the client software goes to the mail server, asks for all the messages, and downloads them to the desktop. If the recipient replies, the whole process is reversed.

Where FreeBSD Fits In

The server section is where FreeBSD excels. A properly configured FreeBSD system can process thousands of messages an hour. If you buy good hardware, a FreeBSD system can receive and transmit over 40,000 pieces of email an hour. That's an average of over 11 messages a second, complete with whatever rambling text, monstrous graphics, and overblown HTML the messages include.

The Email Protocol

To many people, email seems like magic; you hit send and the message is transmitted across the ether to the recipient. However, it's actually pretty easy to send email by hand, without using a client. The ability to do this is yet another trick that can be used to debug difficult problems or impress your friends. (If your friends are impressed by nerdy tricks, that is.)

Testing Connectivity

You can determine whether a host can receive mail by using telnet and specifying that you want to connect to a server's SMTP port (25).

...............................................................................................

# telnet hostname 25

...............................................................................................

You can use this technique, first and foremost, to determine whether a mail server is running on a particular system. Let's connect to the local system[1] and check out the mail system:

...............................................................................................

315

#telnet localhost 25

Trying ::1...

Trying 127.0.0.1...

telnet: connect to address 127.0.0.1: Connection refused

telnet: Unable to connect to remote host

#

...............................................................................................

Okay, my laptop isn't running a mail server. Let's try something we'll actually get a response out of:

...............................................................................................

# telnet AbsoluteBSD.com 25

Trying 209.69.178.18...

Connected to AbsoluteBSD.com.

Escape character is '^]'.

220 AbsoluteBSD.com ESMTP Sendmail 8.9.3/8.9.3; Sun, 10 Jun 2001 17:23:15 −0400

(EDT)

...............................................................................................

Voila! We're speaking directly to the mail server. We now know that a mail program is running. This server even tells us that it uses sendmail as a mail−transfer agent, and gives the local date and time.

The most mysterious part of this is the first part of the response. In this case, it's 220. The email protocol says that each response from the server should include both a numerical code and a human−readable response. The sending program only has to look at the leading number; the longer response is there for the convenience of your poor little organic brain.

Talking to an Email Server

Now let's start a conversation with the program. You open negotiations with the helo command and the hostname you're connecting from:

...............................................................................................

helo turtledawn.AbsoluteBSD.com

...............................................................................................

The server responds with something like this:

...............................................................................................

250 AbsoluteBSD.com Hello pedicular.AbsoluteBSD.com [192.168.1.200], pleased to meet you

...............................................................................................

The response includes the response code (250) and the hostname you're talking to (http://absolutebsd.com/). The "hello" means that the server is willing to talk to you, and it gives the host name of the machine you are connecting from. In this case, the DNS on the server indicates that 192.168.1.200 is actually called http://pedicular.absolutebsd.com/.

You then tell the mail server who your message is from:

...............................................................................................

mail from: mwlucas@AbsoluteBSD.com

...............................................................................................

316

The server should tell you that you're allowed to send mail:

...............................................................................................

250 mwlucas@AbsoluteBSD.com... Sender ok

...............................................................................................

If the server is not accepting mail from your address or your location, it will tell you here. If everything's all right, you name the recipient with the rcpt to: command:

...............................................................................................

rcpt to: mwlucas@AbsoluteBSD.com

250 mwlucas@AbsoluteBSD.com... Recipient ok

...............................................................................................

At this point, the mail server you're talking to knows both the sender and the recipient. (This is the most common place where email transmission is rejected. See the "Relay Control" section that follows.) Now you're ready to send your email. Issue the data command:

...............................................................................................

data

354 Enter mail, end with "." on a line by itself

...............................................................................................

You can type whatever message you like here. Just like the message says, when you're done enter a single period on a line by itself. The following example sends the words "Test message":

...............................................................................................

Test message

.

...............................................................................................

After you type your lone period, the mail server will give you an okay message:

...............................................................................................

250 RAA03288 Message accepted for delivery

...............................................................................................

Type quit to exit:

...............................................................................................

quit

221 AbsoluteBSD.com closing connection Connection closed by foreign host.

#

...............................................................................................

This technique can be used for both good and evil. As an administrator, you can test your email configuration without mucking with a client that might obscure test results.[2] However, it's also trivial to forge email, simply by creating your own mail from: statement.

Who Uses the Email Protocol?

The email protocol is used when one email server transmits messages to another. It is also used when a desktop email client wants to send a message to its server.

317