Archive for the ‘SMTP’ Category

This tutorial explains how you can install and configure SquirrelMail on a RedHat/CentOS/Fedora based mail server which uses Sendmail and Apache.


Primary Mail Server: linuxbox4 (
Domain Name:
Trusted IP Pool:

Note: Replace domain name and system name and IP according to your scenario.


1.  DNS is configured with proper MX record.
2.  All necessary packages/ softwares are installed.

Step 1:

Configure all service to start at boot time.

chkconfig sendmail on
chkconfig httpd  on
chkconfig dovecot on

Step 2:

Configure /etc/hosts file. In this scenario /etc/hosts file should look like this:    linuxbox4 

Step 3:
Outgoing Mail Server Configuration (Sendmail):
Open /etc/mail/ file and change the following two lines.

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl 


dnl DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl 
dnl FEATURE(`accept_unresolvable_domains')dnl 

Save and exit.
- First line here enables sendmail to receive incoming emails on all  installed the NICs. Otherwise mail server would only be able to receive  mails from it.

- Second line here tells sendmail, do not receive emails from mail  servers whose PTR record is not configured in DNS server. This is a  basic level SPAM control settings in sendmail.
Generate file from file.
m4 /etc/mail/ > /etc/mail/

Step 4:

Allow RELAY for trusts (organization's) IP addresses that you want to permit sending emails using this mail server. Open /etc/mail/access in this file we specify all those addresses that will be sending emails through this mail server. At the end of this file add the following line:
192.168.0 RELAY 

Save and exit and convert this text database into DB format by following command.
makemap hash access.db < access

Step 5:

Tell sendmail that it will be acting as a primary mail server for "" domain. We do this by adding domain name in /etc/mail/local-host-names. If this server is acting as a mail server for more then one domains then add names of all of the domains in this file on separate line. Open /etc/mail/local-host-names and add "" at the end of this file. Note: A mail server can act as a primary mail server for more then one domains at the same time and as well as can act as a primary and secondary mail server for more than one domain at the same time.  

Step 6:

All system users are mail users as well. Now create mail only users. useradd -s /usr/sbin/smrsh mailuser1 useradd -s /usr/s2n/smrsh mailuser1 Also set their passwords: passwd mailuser1 passwd mailuser2  

Step 7:

Finally restart sendmail service. service sendmail restart

Step 8:

Incoming Mail Server Configuration (Dovecot): Open /etc/dovecot.conf and change the following lines. From:
#protocols = imap  pop3


protocols = imap imaps pop3 pop3s  

Save and exit and restart dovecot service.
service dovecot restart

Step 9:

Webserver Configuration (Apache): Apache  comes  pre-configured, you  just  have  to  change the ServerName parameter  in /etc/httpd/conf/httpd.conf  file and restart the service, that’s all. Open /etc/httpd/conf/httpd.conf  and set the ServerName parameter.

Save and exit and restart httpd service.
service httpd restart

Installation & Configuration of Squirrelmail 

•  Check that Squirrelmail is installed on the system. # rpm –q squirrelmail •  If squirrelmail is not installed on the system then install it through rpm: # rpm –ivh squirrelmail •  Now go to the squirrelmail directory, located in /usr/share. # cd /usr/share/squirrelmail •  Then go to the config directory: # cd config •  Now run one of the following commands to configure squirrelmail. # ./ OR perl •  Now select option 1 (Organization Preferences). Organization Name  :  YOUR_ORG_NAME Organization Title  :  YOUR_ORG_NAME Webmail  Provider link    :  http://YOUR_ORG_SITE_ADDRESS Provider name  :  YOUR_ORG_NAME •  Now select option 2 (Server Settings). Domain                   : Sendmail or SMTP :  Sendmail IMAP Server          :  localhost IMAP Port               :  143 Server software     :  uw Delimiter                :  / •  Now select option 3 (Folder Settings). Default Folder Prefix                : mail/ Show Folder Prefix Option       : true Trash Folder                            : Trash Sent Folder                              : Sent Drafts Folder                           : Drafts By default, move to trash        : true By default, move to sent         : true By default, save as draft          : true List Special Folders First         : true Show Special Folders Color    : true Auto Expunge                          : true Default Sub. of INBOX            : false Show 'Contain Sub.' Option    : true Default Unseen Notify             : 2 Default Unseen Type              : 1 Auto Create Special Folders   : true Folder Delete Bypasses Trash  : false Enable /NoSelect folder fix   : false •  Now select option 4 (General Settings). Data Directory                       : /var/lib/squirrelmail/prefs/ Attachment Directory            : /var/spool/squirrelmail/attach/ Directory Hash Level            : 0 Default Left Size                   : 150 Usernames in Lowercase     : false Allow use of priority              : true Hide SM attributions             : false Allow use of receipts            : true Allow editing of identity        : true Allow editing of name          : true Remove username from header : false Allow server thread sort       : true Allow server-side sorting     : true Allow server charset search : true Enable UID support             : true PHP session name              : SQMSESSID Location base                       : •  Now choose option 8 (Plugins) and select the plugins that you wish to provide to your webmail users. •  Now open the browser with the following link: http://YOUR_SITE_ADDRESS/webmail OR

SpamAssassin sample procmailrc

Posted: September 29, 2008 in SENDMAIL, SMTP
# SpamAssassin sample procmailrc
# ==============================

# The following line is only used if you use a system-wide /etc/procmailrc.
# See procmailrc(5) for infos on what it exactly does, the short version:
#  * It ensures that the correct user is passed to spamd if spamc is used
#  * The folders the mail is filed to later on is owned by the user, not
#    root.

# Pipe the mail through spamassassin (replace 'spamassassin' with 'spamc'
# if you use the spamc/spamd combination)
# The condition line ensures that only messages smaller than 250 kB
# (250 * 1024 = 256000 bytes) are processed by SpamAssassin. Most spam
# isn't bigger than a few k and working with big messages can bring
# SpamAssassin to its knees.
# The lock file ensures that only 1 spamassassin invocation happens
# at 1 time, to keep the load down.
:0fw: spamassassin.lock
* < 256000
| spamassassin

# Mails with a score of 15 or higher are almost certainly spam (with 0.05%
# false positives according to rules/STATISTICS.txt). Let's put them in a
# different mbox. (This one is optional.)
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "probably-spam".
* ^X-Spam-Status: Yes

# Work around procmail bug: any output on stderr will cause the "F" in "From"
# to be dropped.  This will re-add it.
# NOTE: This is probably NOT needed in recent versions of procmail
* ^^rom[ ]
  LOG="*** Dropped F off From_ header! Fixing up. "

  :0 fhw
  | sed -e '1s/^/F/'

Forwarding all incoming mails

Posted: September 23, 2008 in SENDMAIL, SMTP

Forwarding all incoming mails

Typical situation: So far you have used address A. Now you have a new address (B) or are using another address (B) temporarily and you want all mails received at A to be forwarded to address B.

How do I forward all mails from A to B?

Create the file “$HOME/.forward” with only the address B in it. (The program which receives the mail hopefully knows the system of forwarding by the “forward file”.) The permissions of the “forward” must be “600”. [Could be OS specific, but nevertheless is a good idea.]

Let us assume the following values for the two addresses A and B:

	address A := ""
	address B := ""

Now create the “forward file” on a host on the domain “”:

	echo "" > $HOME/.forward

That’s it!

Make sure that you do not create “loops”, ie creating a “forward file” on both system, sending all the mail from the one system to the other.




Forwarding to more than one address

Keeping a local copy

Assume you receive mail at address A. You forward all mails to address B but you want a copy of *all* mails sent to address C. Then put “\C, B” into your “forward file”. The backslash (“\”) before address C will tell the MTA to send a copy to C. And the “B” tells the MTA to forward the mail to address B.


	$ cat $HOME/.forward

With this you can also leave a copy of your mail in the local mailbox by specifying your local userid:

	$ cat $HOME/.forward

If you want to change the received mail before forwarding it then you must use a “filter” program.




Forwarding one mail

Forwarding a single mail is as easy as using the command “forward” (“f”) from the Folder Menu. You then have to answer the following prompts: (1) edit (prompt for confirmation), (2) send (prompt for addresses), (3) subject (prompt for new/changed subject).

Prompt#1: To edit ot not to edit – that is the question: [*]

Command: Forward                              Edit outgoing message? (y/n) y

You should answer with ‘y’ for two reasons:

Header weeding
The header of the mail is not weeded by default. Please do so to cut down on the message!   

Info for recipients
It is not always obvious why you forwarded the mail. Please add a note saying why you did so. Instruct the reader what to do, eg “please reply to sender” or “please reply to me”. Or just say “for your information” or “just for laughs”. Whatever. Just say *something* about it!   

Prompt#2: Send. “Who shall receive this?”

Send the message to:

Now enter the recipients’ addresses or aliases. If you don’t enter an address then this will abort the command and you will have to start again.

If you want to continue but don’t know the address or alias of the recipient here then just enter something (eg a dot – ‘.’) – you can correct it later via the “h)eaders” menu:


Send the message to: .

Prompt#3: Subject: “What’s it all about?”

Subject: Re: previous subject line (fwd)

ELM suggest you use the same Subject line as the forwarded mail had and adds “(fwd)” to notify that this is a forwarded mail. However, you need not accept this – you can and should always improve the information in the Subject line!

After entering the Subject ELM will call the editor:

Invoking editor...

From now on you probably know how to continue.

Forwarding more than one mail

Situation: You are looking at a folder and you want to forward several of the mails.

Short answer:

  • 0) Change to the folder with ELM.
  • 1) Tag the mails to forward.
  • 2) Save the tagged mails to a seperate folder.
  • 3) Send the folder.

Longer answer:

  • 0) Use “c” to change to the folder which contains the mails to forward.
  • 1) Use “t” to tag all the mails to be forwarded.
  • 2) Use “s” to save all tagged mails to a file, eg “foo”.
  • 3) Send the file “foo” to the addressee.


TODO: Describe how to “send a folder”. Note: If the file is big then you should compress it first.



Compression of files is usually done with either “compress” or “gzip”. Compressing means to use a code to represent the data in a smaller form. This also means that every bit of information is used, especially the highest or eigth bit. Characters with the highest bit are not “text” any more and thus you get a problem transferring these with email. Therefore you have to convert the compressed file to a text file before sending it. This is usually done with “uuencode”.


Example:  'gzip file | uuencode | elm -s "forwarded mails" addressee'

Note: The receiver of such a file should have the necessary programs to decode the file and to decompress it, too. So you should ask whether the receiver actually has these programs.

Examples for decoding “uuencoded” files and decompressing the result:

gzip:      'uudecode file | gunzip'
compress:  'uudecode file | uncompress'

Note: The program “BinHex” does the same as “uuencode”, only it uses a different code. The idea behind the program is the same, though, ie convert “binary” data to “text” data. “BinHex” is used on Macintoshes.



Change of Address

“No account is forever!” – so the saying goes. But what if your the account is closed? Then you certainly need a way to have your mail forwarded.

Several situations are possible: (1) Your account survives for a while. Then you can either have tour mail forwarded with the .forward method or even use a filter or “vacation” to announce your new address. (2) Your account will be terminated. In this case you should ask the admins to forward your mail, but this certainly creates more work. (3) You get yourself a “permanent address” to use always.


Permanent Email Address

For every problem there is someone on the net to solve it. [That’s what I say. :-] And to solve the “dying account problem” some sites are specializing in being “permanent addresses”. They give you an address and they will keep it for your so that it may be permanent. Sure, it costs money, but the idea of never having to lose a mail and never having to tell people about your new address is nice.

TODO: list of post office boxes. [960217]

Technical Notes

The “forward mechanism” works via the -> MTA. Thus you can read a bit about this in the manual to the used MTA, eg “man sendmail”:

In addition, if there is a .forward file in a recipient's home directory,
sendmail forwards a copy of each message to the list of recipients that
file contains.  Aliasing can be prevented by preceding the address with a


  • Which permissions for the forward file for which system and MTA?


ClamAV is a popular tool which scans e-mail for Windows-based viruses1. It can work in several manners, such as the traditional Unix way of accepting the data through stdin and sending reports out through stdout, stderr and/or an appropriate exit code, or it can be used as a sendmail milter.

The principle of a sendmail milter is simple. As the mail is coming down the pipe from the remote host, sendmail feeds it through the milter and then waits for the milter’s reaction. If the reaction is “all is well” then processing carries on as usual. If, on the other hand, the result of the milter operation is “I didn’t like this!” then the mail is rejected right there and then.

The aim of this becomes apparent in the current climate of ‘Net abuse in which the number of junk e-mails and virus infections2 outweighs the amount of genuine e-mail by far, and in which viruses routinely forge the From: address from which they claim to be sent. If we were to accept the mail, discover that it was infected after having accepted it, and then strive to comply with the relevant RFC which states that the sender must be informed in the event of mail not being delivered to the final recipient, we’d be bouncing mail back to innocent bystanders whose only mistake (admittedly a big mistake given the abysmal security track record of the most widespread operating system for desktop PCs) was to have their e-mail address in a friend’s address book or in the clear on a web page.

Note that bouncing the original mail back on the one hand, and sending a thoughtful message saying “Your message to XYZ was not delivered because it contained virus ABC” on the other are both equally abusive!

There is only one way we can reject an infected mail outright without generating an abusive bounce, and that is to reject the mail during the SMTP session in just the same way you’d reject spam from a blacklisted IP address or domain. This is precisely the purpose of using ClamAV as a sendmail milter.

I’ll be assuming that you’re not a total newbie in this document. It is assumed that you’re familiar with compiling software and playing with configuration files, above all sendmail’s configuration files.

Step 1 – Compiling sendmail

If you’re using a binary distribution of sendmail prepared by a Linux distribution supplier such as Debian, Mandrake, SuSE or Red Hat/Fedora, the chances are that your binary has been compiled with milter support and you can skip this part and move straight on to step 2. As a general rule, if you have a file called libmilter.a in /usr/lib or /usr/local/lib and a directory called libmilter in /usr/include or /usr/local/include, then your version of sendmail has been compiled with libmilter support. If not, read on.

Grab a source tarball from a mirror (see for a list of mirrors) and untar the tarball. As of writing this (23/JUL/2004) the latest stable version of sendmail is 8.13.0.

Now set it up so that milter support will be added. Go into the devtools/Site directory under the source root and edit (or create if it doesn’t already exist) site.config.m4 so that it contains these 2 lines:

APPENDDEF(`conf_sendmail_ENVDEF', `-DMILTER')

Now go back to the source root and build/install sendmail as usual.

Before running sendmail, we’ll need to build libmilter. Go into the libmilter directory under the sendmail source tree root and run:

# sh Build
# make install

The libmilter library and include files are now installed.

Step 2 – Compiling ClamAV

Start by creating the “clamav” user and group as which the milter will run (it’s not a good idea for it to run as root):

# groupadd clamav
# useradd -g clamav clamav

Create the directory /usr/local/share/clamav in which we’ll be instructing ClamAV to put its virus signature database, then give the directory appropriate permissions:

# mkdir /usr/local/share/clamav
# chown clamav:clamav /usr/local/share/clamav

Now grab the ClamAV source from

Untar the tarball, build and install ClamAV:

# tar -xzf clamav-0.75.tar.gz
# cd clamav-0.75
# ./configure --disable-clamuko --enable-milter --with-dbdir=/usr/local/share/clamav
# make
# make install

Step 3 – Configuring and starting ClamAV

No particular “–prefix=…” option was given while compiling ClamAV, meaning that its installation prefix is the default /usr/local. ClamAV will therefore expect to find its configuration file in /usr/local/etc/clamav.conf. The sample configuration in the etc directory under the ClamAV source tree root is well commented and should give you plenty of information on what needs changing and what it should be changed to.

Once your clamav.conf file is set up in /usr/local/etc you can start the ClamAV daemon:

# /usr/local/sbin/clamd

It is also recommended that you make sure clamd is started when the machine boots. You can do this by appending the required command to your /etc/rc.d/rc.local file:

# echo "/usr/local/sbin/clamd" >> /etc/rc.d/rc.local

Next, before ClamAV can recognise viruses it needs a signature database. Furthermore, this database must be kept up to date as new varieties of virus are being released every day. ClamAV provides a tool called freshclam for this. This tool also needs a configuration file, /usr/local/etc/freshclam.conf. The sample provided in the ClamAV distribution can also be used as a starting point for your own configuration.

Once that’s set up, we need to grab an initial virus signature database. We’ll be logging the database retrieval in /var/log/clam-update.log, so create the file and above all give it permissions such that freshclam (running as user clamav, group clamav) will have write access to it:

# touch /var/log/clam-update.log
# chown clamav:clamav /var/log/clam-update.log
# chmod 640 /var/log/clam-update.log

Now invoke freshclam and get it to download the latest definitions (this can take some time on a slower connection):

# /usr/local/bin/freshclam -l /var/log/clam-update.log
ClamAV update process started at Sat Jul 24 17:04:12 2004
Reading CVD header (main.cvd): OK
Downloading main.cvd [*]
main.cvd updated (version: 24, sigs: 21793, f-level: 2, builder: tomek)
Reading CVD header (daily.cvd): OK
Downloading daily.cvd [*]
daily.cvd updated (version: 420, sigs: 1062, f-level: 2, builder: tomek)
Database updated (22855 signatures) from (

If you get a warning about there being no support for digital signatures while downloading the virus definition files, it’s because you don’t have the GNU MP arbitrary precision mathematical libraries installed. These are available from While they’re not absolutely necessary, they are strongly recommended because they help ClamAV provide greater security and data integrity.

/var/log/clam-update.log should look something like this now:

ClamAV update process started at Sat Jul 24 17:04:12 2004
main.cvd updated (version: 24, sigs: 21793, f-level: 2, builder: tomek)
daily.cvd updated (version: 420, sigs: 1062, f-level: 2, builder: tomek)
Database updated (22855 signatures) from (

It will also contain the warning about the lack of support for digital signatures if the GMP libraries are not installed.

This update process should be automated and should happen at least twice a day. As root, run crontab -e and create this cron job:

# Update ClamAV database twice a day
0 2,13 * * * /usr/local/bin/freshclam --quiet -l /var/log/clam-update.log

Now you can test the software to make sure it’s installed correctly. ‘cd’ into the test directory under the ClamAV source tree root. You’ll see several files in there which contain ClamAV test signatures that ClamAV should pick up. Try scanning the ‘test’ file:

# clamdscan test
test: ClamAV-Test-Signature FOUND

----------- SCAN SUMMARY -----------
Infected files: 1
Time: 0.006 sec (0 m 0 s)

If you get something like this:

# clamdscan test
connect(): No such file or directory
ERROR: Can't connect to clamd.

----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.003 sec (0 m 0 s)

then the chances are that clamd isn’t running. Try launching it and checking that it is indeed running afterwards:

# /usr/local/sbin/clamd
# ps ax | grep clamd | grep -v grep
11752 ?        S      0:00 /usr/local/sbin/clamd

If clamd refuses to start then double-check your /usr/local/etc/clamav.conf file and the permissions on all the objects it references. Remember that clamd runs as user clamav, group clamav.

Step 4 – Tying ClamAV into sendmail

First we need to start the daemon, clamav-milter, which sets up the unix socket that sendmail will use, and which therefore acts as a go-between between sendmail and the clamd analyser:

# /usr/local/sbin/clamav-milter -l -o -q /var/milter/clmilter.sock

`man clamav-milter’ will give full explanations on the options in the above command line. This particular combination scans all inbound and outbound mail (-o) as well as that sent from within the LAN (-l) and suppresses messages to postmaster (-q) each time a virus is detected – I’m getting about 10 a day (which is a lot less than some) so I don’t want to receive notification each and every time.

Also, add the command to your /etc/rc.d/rc.local so that the daemon is started whenever the machine is:

# echo "/usr/local/sbin/clamav-milter -l -o -q /var/milter/clmilter.sock" >> /etc/rc.d/rc.local

The final step is to get sendmail to use the milter. To do so, add the following lines to your /etc/mail/ file:

INPUT_MAIL_FILTER(`clmilter',`S=local:/var/milter/clmilter.sock, F=, T=S:4m;R:4m')dnl
define(`confINPUT_MAIL_FILTERS', `clmilter')

Build a new and restart sendmail, you’re ready to start blocking viruses.

If you are looking to send email with attachment via shell script or at shell prompt/command line (read as bash prompt), use mutt command.

Mutt is a small but very powerful text based program for reading electronic mail under UNIX /Linux operating systems, including support for color terminals, MIME, and a threaded sorting mode.

Please note that mutt is a pure MUA and cannot send e-mail without proper email server . You need a working Mail Transfer Agent (MTA) such as sendmail or postfix. I am assuming that you have configured email server.

Install mutt

If mutt is not installed, use apt-get or yum or up2date command as follows (login as a root user):

(A) Debian Linux / Ubuntu Linux user use following command to install mutt:
# apt-get install mutt

B) Fedora / CentOS or Red Hat Linux (RHEL) user can use following command to install mutt:
# yum install mutt
# up2date mutt

C) FreeBSD user use following command to install mutt via pkg_add command:
# pkg_add -v -r mutt

How do I send email attachments from a command prompt?

1) Use mutt command as follows to send an email with attachment:
$ mutt -s "Test mail" -a /tmp/file.tar.gz < /tmp/mailmessage.txt


  • – is the recipient
  • /tmp/mailmessage.txt – is the main body of the e-mail (read message from the file “mailmessage.txt”)
  • /tmp/file.tar.gz – is an attachment (with option -a)
  • “Test mail” – is a subject line (option -s)


Send mail bash script

Here is what you need to put in a shell script:

# script to send simple email
# email subject
# Email To ?
# Email text/message
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE



Posted: September 16, 2008 in SENDMAIL, SMTP
Tags: ,


Create a file procmailrc in /etc and out following

# vi /etc/procmailrc

| /usr/bin/spamc
* ^X-Spam-Status: Yes
Save and close

For fine tuning edit /etc/mail/spamassassin/ and put following

# These values can be overridden by editing ~/.spamassassin/
# (see spamassassin(1) for details)

# These should be safe assumptions and allow for simple visual sifting
# without risking lost emails.

required_hits 5.0
rewrite_header Subject *****SPAM*****
report_safe 0

whitelist_from *

blacklist_from kumrah_1974@ADSTRA.COM
blacklist_from ejirvtfi@GFAX.GNCOMTEXT.COM

header CONTAINS_VIG Subject =~ /viagra, Cialix Pills, sex, xxx, penis, pussy/
body CONTAINS_PEN /viagra, sex, xxx, penis, pussy/
score CONTAINS_VIG 1.5
score CONTAINS_PEN 1.5
describe CONTAINS_VIG Bad Word
describe CONTAINS_PEN Bad Word


Save and close

This file from my server config file …….