Home » , » Managing Mail and News Servers in Linux

Managing Mail and News Servers in Linux

Written By Sajib Barua on Tuesday, August 21, 2012 | 12:20 AM

previous Linux Servers
Electronic mail (e-mail) is one of the popular services available on Internet hosts. E-mail software comes in two parts: a mail transport agent (MTA), which physically sends and receives mail messages, and a mail user agent (MUA), which reads messages and prepares new messages. This chapter describes the e-mail service and shows you how to configure the sendmail server on a Linux PC.
Internet newsgroups provide another convenient way, besides e-mail, to discuss various topics and share your knowledge with others. Linux comes with the software you need to read newsgroups and set up your own system as a news server. This chapter also describes how to configure and run the popular InterNetNews server and shows how to set up local newsgroups for your corporate intranet (or even your home network).
Installing the Mail Server
Depending on the choices you made during your Linux installation, you may have already installed the mail server software on your system. You can choose from several mail servers, such as exim, postfix, and sendmail — your sendmail is briefly covered in this chapter. If sendmail is not installed, you can easily install it.
In Debian, Ubuntu, and Xandros, type dpkg -l sendmail* to see if sendmail is installed. In Fedora and SUSE, type rpm -qa | grep sendmail to see if the sendmail package is installed.
In Debian and Ubuntu, type apt-get install sendmail to install the sendmail server. In Fedora, log in as root, and type rpm -ivh sendmail*. In SUSE, click Software Management in the YaST Control Center’s Software category. Then use YaST’s search facility to find the sendmail package and install it.
Using sendmail
To set up your system as a mail server, you must configure the sendmail mail transport agent properly. sendmail has the reputation of being a complex but complete mail-delivery system. Just one look at sendmail’s configuration file — /etc/mail/sendmail.cf in Fedora or /etc/sendmail. cf in SUSE — can convince you that sendmail is indeed complex. Luckily, you don’t have to be an expert on the sendmail configuration file. All you need is one of the predefined configuration files — such as the one installed on your system — to use sendmail.
Your system already has a working sendmail configuration file — /etc/ mail/sendmail.cf. The default file assumes you have an Internet connection and a name server. Provided that you have an Internet connection and that your system has an official domain name, you can send and receive e-mail from your Linux PC.
To ensure that mail delivery works correctly, your system’s name must match the system name that your ISP has assigned to you. Although you can give your system any hostname you want, other systems can successfully deliver mail to your system only if your system’s name is in the ISP’s name server.
A mail-delivery test
To try the sendmail mail transfer agent, you can use the mail command to compose and send a mail message to any user account on your Linux system. As a test, compose a message and send it to yourself. For example, here’s how to send a message using the mail command. (Input appears in boldface.)
mail edulaney
Subject: Testing e-mail
This is from my Linux system.
.

The mail command is a simple mail user agent. In the preceding example, the addressee (edulaney) is specified in the command line. The mail program prompts for a subject line. Following the subject, enter the message and end it with a line that contains only a period. You will be prompted for a Cc:, but leave that blank. After ending the message, the mail user agent passes the message to sendmail (the mail transport agent) for delivery to the specified address. sendmail delivers the mail message immediately. To verify the delivery of mail, type mail to run the mail command again and read the message.
If any of your mail server software is not properly installed, you should be prompted during this test to install any needed components and resolve the problem.
Thus, the initial sendmail configuration file is adequate for sending and receiving e-mail, at least within your Linux system. External mail delivery also works, provided that your Linux system has an Internet connection and a registered domain name.
If you have an ISP account that provides your Linux system with a dynamic IP address, you have to use a mail client such as Evolution or Mozilla Mail, which contacts your ISP’s mail server to deliver outbound e-mail.
The mail-delivery mechanism
On an Internet host, the sendmail mail transport agent delivers mail using the Simple Mail Transfer Protocol (SMTP). SMTP-based mail transport agents listen to TCP port 25 and use a small set of text commands to exchange information with other mail transport agents. SMTP commands are simple enough that you can use them manually from a terminal to send a mail message. The telnet command opens a TELNET session to port 25 (the port on which sendmail expects SMTP commands). The sendmail process on the Linux system immediately replies with an announcement.
You can type HELP to view a list of SMTP commands. To get help on a specific command, type HELP commandname. Type HELO localhost to initiate a session with the host. The sendmail process replies with a greeting. To send the mail message, start with the MAIL FROM: command, which specifies the sender of the message. Next, use the RCPT TO: command to specify the recipient of the message. If you want to send the message to several recipients, provide each recipient’s address with the RCPT TO: command.
To enter the mail message, use the DATA command. In response to the DATA command, sendmail displays an instruction that you have to end the message with a period on a line by itself. After doing this, the sendmail process displays a message indicating that the message is accepted for delivery. You can then quit the sendmail session with the QUIT command.
The sendmail configuration file
You don’t have to understand everything in the sendmail configuration file, sendmail.cf, but you need to know how that file is created. That way, you can make minor changes if necessary and regenerate the sendmail.cf file.
In SUSE, you can configure sendmail through the YaST Control Center — choose System➪Control Center (YaST) from the main menu. Click Network Services in the left side of the window, and then click Mail Transfer Agent in the right side of the window. YaST displays a window that you can use to configure sendmail. First you specify the general settings, then the settings for outgoing mail, and finally the settings for incoming mail. After you exit the mail configuration utility, YaST stores the mail settings in the files /etc/ sysconfig/sendmail and /etc/sysconfig/mail and then runs SuSE config to update the sendmail configuration file (/etc/sendmail.cf).
You can also generate the sendmail.cf file from a number of m4 macro files (text files in which each line eventually expands to multiple lines that mean something to some program). These macro files are organized into a number of subdirectories in the /usr/share/sendmail-cf directory in Fedora or the /usr/share/sendmail directory in SUSE. You can read the README file in that directory to find out more about the creation of sendmail configuration files.
The m4 macro processor
The m4 macro processor generates the sendmail.cf configuration file, which comes with the sendmail package in Linux. The main macro file, named sendmail.mc, generic_linux.mc, or linux.mc, is included with the sendmail package.
So what’s a macro? A macro is basically a symbolic name for code that handles some action, usually in a shorthand form that substitutes for a long string of characters. A macro processor such as m4 usually reads its input file and copies it to the output, processing the macros along the way. The processing of a macro generally involves performing some action and generating some output. Because a macro generates a lot more text in the output than merely the macro’s name, the processing of macros is referred to as
macro expansion.
The m4 macro processor is stream-based. That means it copies the input characters to the output while it’s busy expanding any macros. The m4 macro processor does not have any concept of lines, so it copies newline characters (that mark the end of a line) to the output. That’s why in most m4 macro files you see dnl, an m4 macro that stands for delete through newline. The dnl macro deletes all characters starting at the dnl up to and including the next newline character. The newline characters in the output don’t cause any harm; they merely create unnecessary blank lines. The sendmail macro package uses dnl to avoid such blank lines in the output configuration file. Because dnl basically means delete everything up to the end of the line, m4 macro files also use dnl as the prefix for comment lines.
To see a simple use of m4, consider the following m4 macro file, which defines two macros — hello and bye — and uses them in a form letter:
dnl ###################################################
dnl # File: ex.m4
dnl # A simple example of m4 macros
dnl ###################################################
define(`hello’, `Dear Sir/Madam’)dnl
define(`bye’,
`Sincerely,
Customer Service’)dnl
dnl Now type the letter and use the macros
hello,
This is to inform you that we received your recent inquiry.
We will respond to your question soon.
bye

Type this text (using your favorite text editor) and save it in a file named ex.m4. You can name a macro file anything you like, but using the .m4 extension for m4 macro files is customary.
Before you process the macro file by using m4, note the following key points about the example:
  • Use the dnl macro to start all the comment lines, as in the first four lines in the example.
  • End each macro definition with the dnl macro. Otherwise, when m4 processes the macro file, it produces a blank line for each macro definition.
  • Use the built-in m4 command define to define a new macro. The macro name and the value are both enclosed between a pair of left and right single quotes (‘ . . . ’). Note that you cannot use the plain single quote to enclose the macro name and definition.
Now process the macro file ex.m4 by typing the following command:
m4 ex.m4
m4 processes the macros and displays the following output:
Dear Sir/Madam,
This is to inform you that we received your recent inquiry.
We will respond to your question soon.
Sincerely,
Customer Service

Sounds just like a typical customer service form letter, doesn’t it?
If you compare the output with the ex.m4 file, you see that m4 prints the form letter on standard output, expanding the macros hello and bye into their defined values. If you want to save the form letter in a file called letter, use the shell’s output redirection feature, like this:
m4 ex.m4 > letter
What if you want to use the word hello or bye in the letter without expanding them? You can do so by enclosing these words in a pair of single quotes (‘ . . . ’). You have to do so for other predefined m4 macros, such as define. To use define as a plain word, not as a macro to expand, type ‘define’.
The sendmail macro file
The simple example in the preceding section gives you an idea of how m4 macros are defined and used to create configuration files such as the sendmail.cf file. You find many complex macros stored in files in the /usr/share/sendmail-cf directory in Fedora or the /usr/share/ sendmail directory in SUSE. A top-level macro file (called sendmail.mc in Fedora and linux.mc in SUSE), described later in this section, brings in these macro files with the include macro (used to copy a file into the input stream).
To avoid repeatedly mentioning different file and directory names for different distributions such as Fedora and SUSE, I use the file and directory names for Fedora in the following discussions. The general discussions apply to sendmail in all Linux distributions, but you have to replace the file and directory names with those for your specific distribution.
By defining its own set of high-level macros in files located in the /usr/ share/sendmail-cf directory, sendmail essentially creates its own macro language. The sendmail macro files use the .mc extension. The primary sendmail macro file you configure is sendmail.mc, located in the / etc/mail directory.
Compared to the /etc/mail/sendmail.cf file, the /etc/mail/send mail.mc file is shorter and easier to work with. Here are some lines from the /etc/mail/sendmail.mc file that comes with Fedora:
divert(-1)dnl
dnl #
dnl # This is the sendmail macro config file for m4. If you make changes to
dnl # /etc/mail/sendmail.mc, you will need to regenerate the
dnl # /etc/mail/sendmail.cf file by confirming that the sendmail-cf package is
dnl # installed and then performing a
dnl #
dnl # /etc/mail/make
dnl #
include(`/usr/share/sendmail-cf/m4/cf.m4’)dnl
VERSIONID(`setup for linux’)dnl
OSTYPE(`linux’)dnl
dnl #
dnl # Do not advertise sendmail version.
dnl #
dnl define(`confSMTP_LOGIN_MSG’, `$j Sendmail; $b’)dnl
dnl #
dnl # default logging level is 9, you might want to set it higher to
dnl # debug the configuration
dnl #
dnl define(`confLOG_LEVEL’, `9’)dnl
dnl #
dnl # Uncomment and edit the following line if your outgoing mail needs to
dnl # be sent out through an external mail server:
dnl #
dnl define(`SMART_HOST’, `smtp.your.provider’)dn
. . . lines deleted . . .
dnl #
dnl MASQUERADE_AS(`mydomain.com’)dnl
dnl #
dnl # masquerade not just the headers, but the envelope as well
dnl #
dnl FEATURE(masquerade_envelope)dnl
dnl #
dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well
dnl #
dnl FEATURE(masquerade_entire_domain)dnl
dnl #
dnl MASQUERADE_DOMAIN(localhost)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl
dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl MAILER(cyrusv2)dnl
If you make changes to the /etc/mail/sendmail.mc file, you must generate the /etc/mail/sendmail.cf file by running the sendmail.mc file through the m4 macro processor with the following command. (You have to log in as root.)
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
The comments also tell you that you need the sendmail-cf package to process this file.
From the previous section’s description of m4 macros, you can see that the sendmail.mc file uses define to create new macros. You can also see the liberal use of dnl to avoid inserting too many blank lines into the output.
The other uppercase words (such as OSTYPE, FEATURE, and MAILER) are sendmail macros. These are defined in the .m4 files located in the subdirectories of the /usr/share/sendmail-cf directory and are incorporated into the sendmail.mc file with the following include macro:
include(`usr/share/sendmail-cf/m4/cf.m4’)dnl
The /usr/share/sendmail-cf/m4/cf.m4 file, in turn, includes the cfhead.m4 file, which includes other m4 files, and so on. The net effect is as follows: As the m4 macro processor processes the sendmail.mc file, the macro processor incorporates many m4 files from various subdirectories of /usr/share/sendmail-cf.
Here are some key points to note about the /etc/mail/sendmail.mc file:
  • VERSIONID(‘setup for linux’) macro inserts the version information enclosed in quotes into the output.
  • OSTYPE(‘linux’) specifies Linux as the operating system. You have to specify this macro early to ensure proper configuration. Placing this macro right after the VERSIONID macro is customary.
  • MAILER(smtp) describes the mailer. According to instructions in the /usr/share/sendmail-cf/README file, MAILER declarations are always placed at the end of the sendmail.mc file and MAILER(smtp) always precedes MAILER(procmail). The mailer smtp refers to the SMTP mailer.
  • FEATURE macros request various special features. For example, FEATURE(`blacklist_recipients’) turns on the capability to block incoming mail for certain usernames, hosts, or addresses. The specification for what mail to allow or refuse is placed in the access database (stored in /etc/mail/access.db file). You also need the FEATURE(`access_db’) macro to turn on the access database.
  • MASQUERADE_AS(`mydomain.com’) causes sendmail to label outgoing mail as having come from the host mydomain.com (replace my domain with your domain name). The idea is for a large organization to set up a single sendmail server that handles the mail for many subdomains and makes everything appear to come from a single domain. (For example, mail from many departments in a university appears to come from the university’s main domain name.)
  • MASQUERADE_DOMAIN(subdomain.mydomain.com) instructs send mail to send mail from an address such as user@subdomain.my domain.com as having originated from the same username at the domain specified by the MASQUERADE_AS macro.
The sendmail macros such as FEATURE and MAILER are described in the /usr/share/sendmail-cf/README file. Consult that file to find out more about the sendmail macros before you make changes to the sendmail.mc file.
Syntax of the sendmail.cf file
The sendmail.cf file’s syntax is designed to be easy to parse by the send mail program because sendmail reads this file whenever it starts. Human readability was not a primary consideration when the file’s syntax was designed. Still, with a little explanation, you can understand the meaning of the control lines in sendmail.cf.
Each sendmail control line begins with a single-letter operator that defines the meaning of the rest of the line. A line that begins with a space or a tab is considered a continuation of the previous line. Blank lines and lines beginning with a pound sign (#) are comments.
Often, no space is between the single-letter operator and the arguments that follow the operator, which makes the lines even harder to understand. For example, sendmail.cf uses the concept of a class — essentially a collection of phrases. You can define a class named P and add the phrase REDIRECT to that class with the following control line:
CPREDIRECT
Because everything runs together, the command is hard to decipher. On the other hand, to define a class named Accept and set it to the values OK and RELAY, write the following:
C{Accept}OK RELAY
This command may be slightly easier to understand because the delimiters (such as the class name, Accept) are enclosed in curly braces.
Other, more recent control lines are even easier to understand. For example, the line
O HelpFile=/etc/mail/helpfile
defines the option HelpFile as the filename /etc/mail/helpfile. That file contains help information that sendmail uses when it receives a HELP command.
Table 2-1 summarizes the one-letter control operators used in sendmail. cf. Each entry also shows an example of that operator. This table helps you understand some of the lines in sendmail.cf.
Table 2-1
Control Operators Used in sendmail.cf
Operator
Description
C
Defines a class; a variable (think of it as a set) that can contain several values. For example, Cwlocalhost adds the name localhost to the class w.
D
Defines a macro, a name associated with a single value. For example, DnMAILER-DAEMON  defines the macro n as MAILER-DAEMON.
F
Defines a class thats been read from a file. For example, Fw/etc/mail/local-host-names reads the names of hosts from the file /etc/mail/local-host-names and adds them to the class w.
H
Defines the format of header lines that sendmail inserts into a message. For example, H?P?Return-Path:  <$g> defines the Return-Path: field of the header.
K
Defines a map (a key-value pair database). For example, Karitharith defines the map named arith as the compiled-in map of the same name.
M
Specifies a mailer. The following lines define the procmail mailer: Mprocmail,P=/usr/bin/procmail,F=DFMSPh nu9,S=EnvFromSMTP/HdrFromSMTP,R=EnvToSMTP/ HdrFromSMTP,T=DNS/RFC822/X-Unix,A=procmail -Y  -m  $h  $f  $u.
O
Assigns a value to an option. For example, O  AliasFile=/etc/aliases defines the AliasFile option to /etc/ aliases, which is the name of the sendmail alias file.
P
Defines values for the precedence field. For example, Pjunk=-100 sets to -100 the precedence of messages marked with the header field Precedence:  junk.
R
Defines a rule. (A rule has a left side and a right side; if input the left side, the right side replaces it. This rule is called rewriting.) For example, the rewriting rule R$* ;  $1 strips trailing semicolons.
S
Labels a ruleset you can start defining with subsequent R control lines. For example, Scanonify=3 labels the next ruleset as canonify and ruleset 3.
T
Adds a username to the trusted class (class t). For example, Troot adds root to the class of trusted users.
V
Defines the major version number of the configuration file. For example, V10/Berkeley defines the version number as 10.
Other sendmail files
The /etc/mail directory contains other files that sendmail uses. These files are referenced in the sendmail configuration file, /etc/mail/sendmail.cf in Fedora and /etc/sendmail.cf in SUSE. For example, here’s how you can search for the /etc/mail string in the /etc/mail/sendmail.cf file in Fedora:
grep “\/etc\/mail” /etc/mail/sendmail.cf
Here’s what the grep command displays as a result of the search on a typical Fedora system:
Fw/etc/mail/local-host-names
FR-o /etc/mail/relay-domains
Kmailertable hash -o /etc/mail/mailertable.db
Kvirtuser hash -o /etc/mail/virtusertable.db
Kaccess hash -T<TMPF> -o /etc/mail/access.db
#O ErrorHeader=/etc/mail/error-header
O HelpFile=/etc/mail/helpfile
O UserDatabaseSpec=/etc/mail/userdb.db
#O ServiceSwitchFile=/etc/mail/service.switch
#O DefaultAuthInfo=/etc/mail/default-auth-info
Ft/etc/mail/trusted-users

You can ignore the lines that begin with a hash mark, or number sign (#) because sendmail treats those lines as comments. The other lines are sendmail control lines that refer to other files in the /etc/mail directory.
Here’s what some of these sendmail files are supposed to contain. (Note that not all of these files have to be present in your /etc/mail directory, and even when present, some files may be empty.)
  • /etc/mail/access: Names or IP addresses or both of hosts allowed to send mail (useful in stopping spam — unwanted e-mail).
  • /etc/mail/access.db: Access database generated from the /etc/mail/access file.
  • /etc/mail/helpfile: Help information for SMTP commands.
  • /etc/mail/local-host-names: Names by which this host is known.
  • /etc/mail/mailertable: Mailer table used to override how mail is routed. (For example, the entry comcast.net smtp:smtp.comcast. net tells sendmail that mail addressed to comcast.net has to be sent to smtp.comcast.net.)
  • /etc/mail/relay-domains: Hosts that permit relaying.
  • /etc/mail/trusted-users: List of users allowed to send mail using other user’s names without a warning.
  • /etc/mail/userdb.db: User database file containing information about each user’s login name and real name.
  • /etc/mail/virtusertable: Database of users with virtual-domain addresses hosted on this system.
The /etc/mail directory sometimes contains other files — /etc/mail/ certs and the files with the .pem extension — that are meant for supporting Privacy Enhanced Mail (PEM) in sendmail by using the STARTTLS extension to SMTP. The STARTTLS extension uses TLS (more commonly known as SSL — Secure Sockets Layer) to authenticate the sender and encrypt mail. RFC 2487 describes STARTTLS. (This RFC is available online at http://ietf.org/rfc/rfc2487.txt.)
If you edit the /etc/mail/mailertable file, you have to type the following command before the changes take effect:
makemap hash /etc/mail/mailertable < /etc/mail/mailertable
Here is an easier way to make sure that you rebuild everything necessary after making any changes — just type the following commands while logged in as root:
cd /etc/mail
make

The first command changes the current directory to /etc/mail, and the second command runs the make command, which reads a file named Makefile in /etc/mail to perform the steps necessary to rebuild everything.
The .forward file
Users can redirect their own mail by placing a .forward file in their home directory. The .forward file is a plain-text file with a comma-separated list of mail addresses. Any mail sent to the user is instead forwarded to these addresses. If the .forward file contains a single address, all e-mail for that user is redirected to that single e-mail address. For example, suppose a .forward file containing the following line is placed in the home directory of a user named emily:
ashley
This line causes sendmail to automatically send all e-mail addressed to emily to the username ashley on the same system. User emily does not receive mail at all.
You can also forward mail to a username on another system by listing a complete e-mail address. For example, you can add a .forward file with the following line to send messages addressed to username wilbur to the mail address wilbur@somewhereelse.net:
wilbur@somewhereelse.net
To keep a copy of the message on the original system, in addition to forwarding to the preceding specified address, add the following line to the .forward file:
wilbur@somewhereelse.net, wilbur\
Simply append the username and end the line with a backslash (\). The backslash at the end of the line stops sendmail from repeatedly forwarding the message.
The sendmail alias file
In addition to the sendmail.cf file, sendmail also consults an alias file named /etc/aliases to convert a name into an address. The location of the alias file appears in the sendmail configuration file.
Each alias is typically a shorter name for an e-mail address. The system administrator uses the sendmail alias file to forward mail, to create a mailing list (a single alias that identifies several users), or to refer to a user by several different names. For example, here are some typical aliases:
brown: glbrown
all: jessica, isaac, alex, caleb, glbrown

After defining any new aliases in the /etc/aliases file, you must log in as root and make the new alias active by typing the following command:
sendmail –bi
next Installing the INN Server




























































































Share this article :

0 comments:

Post a Comment

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Linux - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger