Linux Email

Note: Most of the commands listed below can or should only be executed from the root account.

Control, Configure, Monitor

The program used to control the sending and receiving of Email is sendmail.

  • Normally it runs as a background daemon.
  • It determines and controls how to send internal Email vs external Email to the Internet.
  • The daemon also controls the retrieving of mail from an Email server.

In this document we cover some options that can be used to determine sendmail status.

Examples What it does
sendmail -bp or mailq Displays the status of the mail queue. List Email files waiting to be sent and incoming.
ps ax|grep sendmail Lists the process status of the sendmail daemon. May display something similar to...
128 ? S 0:03 sendmail: accepting connections on port 25
sendmail -bi or newaliases Rebuilds the aliases database. Should be run after any changes are made to the alias file.

top of page

Sendmail configuration file

Most of the parameters to control how sendmail works are stored in /etc/ You can view the contents of this file by using less /etc/

Note: You should not make changes to this file unless you understand sendmail. A simple error in this file can cause sendmail to stop working.

Very few changes should have to be made to the standard supplied file. Here are two main parameters that get changed.

  • Cwlocalhost

top of page

Start/Stop sendmail

Whenever changes are made to the file, sendmail must be stopped and restarted before changes take effect. To do so...

  • cd /etc/rc.d
  • ./sendmail stop
  • ./sendmail start

top of page

Relay setup (SuSE Linux 6.2)

Starting with SuSE Linux 6.2, in order to allow the sending of email there are two procedures that must be set up. If this is not done you will get the message "Relaying not allowed - Error 550". This is a new security feature to prevent someone from using your email server for spam mail.

  • User's IP address most be added to the /etc/hosts file
  • Legal IP addresses or domain names must be added to /etc/mail/access file
    • To allow all IP's in starting with 192.168.1, enter 192.168.1 relay
    • To allow a domain name such as, enter relay

top of page

Aliases for user names

The file /etc/aliases contains alternative or alias names.

  • This can be used to redirect Email to a different user or a group of users.
  • This file can be maintained using a text editor such as vi or the Webmin tool.
  • Changes are not active until the aliases database is rebuilt using eithersendmail BI or newaliases.

Note: upper Vs lower case letters are ignored in both Email names and Domain names. Sending mail to Roger@AHInc is the same as Using upper case letters only makes the name more readable.

  • The first value is always the Email address that the original mail was sent to, i.e. the name used in composition of an Email message, followed by a colon.
  • The second entry can take different forms.
    • It can simply be a new Email address where the mail is forwarded to.
    • It can be a pointer to a file containing several Email addresses.
    • It can be a executable file that filters or further processes the mail.
Examples What it does
sales: all mail sent to 'sales', goes to ''
virusalert: root all mail sent to 'virusalert', goes to the local user 'root'
Majordomo: "|/usr/lib/majordomo/wrapper majordomo" all mail sent to 'Majordomo' is processed by the 'wrapper' program
horizon: "|/usr/lib/majordomo/wrapper resend -l horizon horizon-list" all mail sent to 'horizon' is sent to the names in the file 'horizon-list'

top of page

Getting Email from an Email server

If your connection to the Internet is via a dialup line, the command fetchmail can be used in conjunction with sendmail to get Email from your ISP's server.

  • Fetchmail is normally scheduled by 'cron' to periodically get and send new Email.
  • The only fetchmail command you typically want to execute banally is to run a check to see if any new Email exists on the ISP server.

fetchmail -c Will display the number of messages waiting to be retrieved.

top of page

Stored Email locations
Location Used for
/var/spool/mail Received Email messages are stored in the directory. There is a separate file for each user.
/var/mqueue Email waiting to be sent
/var/log/mail A log of Email sent and received. The contents of the log file can be viewed by the command: less /var/log/mail.
/etc/mail Email configuration files

top of page

Standard Email Client Programs

Most everyone uses an Email client such as Eudora, Outlook, Netscape, etc to send and read Email. You can use the standard Linux mail command to send and read Email. Because this is not a very user-friendly utility, it is recommend to only use the mail command for testing Email. It can be handy for reading Email for the 'root' account.

Examples What it does
  • Allows you to read Email.
  • First displays a summary list of unread Email messages.
  • You can select a message to read the message contents.
  • You can delete messages.
mail roger
  • Creates an Email message to the local user 'roger'.
  • You will be prompted to enter the 'subject' and then the body of the message.
  • Enter a period to exit mail and send the message.
Mail If your domain is not, this will send Email to external user.

A better alternative to mail is to use the Email client pine. Linux usually has pine already installed. It provides help prompts for all commands and is easier to use and understand. To use simply enter pine.

top of page

Automatically Scan Email for Viruses

The following is a summary of how to have sendmail scan for viruses.


  • F-Secure for Linux
  • Amavis


  • F-Secure for Linux
    • Install and configure
  • Cron Job
    • Schedule updates for once an hour via cron
    • Change crontab cromand line parms for daily scan
  • Other
    • Compile and install tnef and xbin. Both files should be placed in /usr/local/bin
    • Compile and install Amavis - ./configure -with-notify-receiver=yes
      add code 8 to scanstatus8 in scanmails to catch suspicious files
    • Change SuSEconfig sendmail (not directly to include amavis.m4 macro
    • Copy amavis.m4 to /usr/share/sendmail/feature/
    • Include new feature in /sbin/conf.d/SuSEconfig.sendmail
      • New entry should be after procmail entry
    • Run SuSEconfig to automatically recreate the new /etc/
      • Check /etc/ for new changes
    • Restart sendmail
    • Send an email message containing the test virus

Bug Fix for SuSE sendmail and Email Scanner

Depending on your system, subprocesses are run as the UID of the local recipient (not 'root'). Calling your local delivery program (usually procmail) might have insufficient privileges to deliver it any further.This usually happens on SuSE Linux 6.0 and greater.

Changes to /etc/

Add the o flag and remove the S flag in the Mlocal, F= section.


Mlocal, P=/usr/sbin/scanmails, F=lsDFMAw5:/|@qSPfhn9, S=10/30,
A=scanmails -Y -a $h -d $u


Mlocal, P=/usr/sbin/scanmails, F=olsDFMAw5:/|@qPfhn9, S=10/30,
A=scanmails -Y -a $h -d $u

top of page

Virtual Email Hosting

Our concept of a virtual Email host...

  • To accept or have all Email for a given domain be sent to a server that is always connected to the Internet. Let's call this the "virtual email server".
  • All Email for the given domain is automatically forwarded to
  • Typically, another server or individual user will access the account of (usually via a dial-up connection) and retrieve all mail.

    To configure the "virtual email server"...

    1. Using Webmin/Sendmail/Address Mapping - add a mapping from the domain to a user mail address. Example: to
    2. Using Webmin/Sendmail/Spam Control - add the new domain. Example: Make sure the relaying services option is selected.
    3. Depending the verion of sendmail, you need to add a Cw entry...
      1. Older versions - Using YAST/sendmail/Advanced mode - add to the existing Local Domains.
      2. Newer versions - to the file /etc/mail/, add
    4. Stop/Start sendmail for changes to take effect.
    5. Change or create an MX record to point to the IP address of the "virtual email server".

top of page

Stopping Spam (Relay)

To prevent your server from being used to send spam mail by relaying email messages, the following configuration changes have to be installed. Without this someone could use your email server to distribute spam mail. To the email receipient it would appear as if your domain sent the email. In addition it can add unneccesary overhead to your server and network, causing access to the Internet and your server to react very slowly.

Newer version of sendmail (>= version 8.9)

Just for your information, the newer version of sendmail keeps the configuration file in /etc/mail/
The older version kept it in /etc/


The file /etc/mail/relay-domains list the domains that you want to allow relaying of email to an outside host.

The following example lists three domain names that would be allowed to relay mail from your server.
Older version of sendmail (< version 8.9)

To stop relaying of spam email, in the SuSE version of Linux, the following files have to be edited.


In this file locate the section that starts with cat <<EOF and ends with EOF.

Just before EOF there should a few lines like...

After this section and before the EOF line, add...


This file may not exist so you may have to create it. This file contains the local IP addresses. Example...

Implement changes

After the above changes have been made you need to....

  • Run SuSEconfig (as root)
  • Restart the sendmail process
    • To stop, enter...
      /etc/rc.d/sendmail stop
    • To start, enter...
      /etc/rd.d/sendmail start

top of page

Send Email © Advanced Horizons, Inc. All Rights Reserved