Monday, February 15, 2010
Wednesday, November 4, 2009
Sendmail Command Line Tips and Tricks
Prints the mail queue's contents, same as /usr/lib/sendmail –bp
Command Line Switches
-B 7bit
Causes sendmail to clear the high-bit of every incoming byte.
-B 8bitmime
Causes sendmail to preserve the high-bit or every incoming byte.
-ba
Uses ARPAnet/Grey-Book protocols to transfer mail.
-bD
Runs as daemon, like –bd, but does not fork and does not detach from controlling terminal.
-bd
Runs as daemon, forks and detaches.
-bH
Purges (zeroes) persistent host status info.
bh
Prints persistent host status info.
bi
Initializes the aliases database.
-bm
Causes sendmail to read and send message (this is the default)
-bp
Prints the contents of the mail queue.
-bs
Runs sendmail on standard I/O.
-bt
Runs sendmail in rule testing mode.
-bv
Verifies address.
-C /tmp/different.cf
Uses different.cf as its configuration file.
-c
Sets HoldExpensive option to true.
-d
set debug mode.
- -d0 – Shows general config
- -d0.1 – Prints version
- -d.04 – Prints local hostname and any aliases for it.
- -d0.15 – Prints the list of delivery agents declared
- -d0.20 – Prints address of each network interface
- -d8 – Traces most DNS lookups
- -d8.1 – Prints failure of low level MX searches.
- -d8.2 – Prints calls to getcanonname
- -d8.3 - Traces dropped local hostnames
- -d8.5 – Shows hostnames tried in getcanonname
- -d8.8 – Shows when MX lookups return the wrong type.
- -d11 – Traces delivery agent calls
- -d11.1 – Traces arguments passed to the delivery agent
- -d11.2 - Prints the user ID that the delivery agent is invoked as
- -d21 – Traces rewriting of addresses
- -d21.1- Traces general ruleset rewriting
- -d21.2 – Traces use of $& macro
- -d21.3 – Shows $> subroutines called
- -d21.4 – Displays result of rewrite
- -d21.15 – Shows $digit replacement
- -d21.35 – shows token by token LHS matching
- -d27 – Traces aliasing
- -d27.1 – Traces general aliasing
- -d27.2 – Traces :include: files, alias self-references, and errors on home
- -d27.3 – Traces the ~/.forward path and the alias wait
- -d27.4 – Prints "not safe" when a file is unsafe to trust
- -d27.9 – Shows uid/gid changes when reading :include: files
- -d35 – Traces macros
- -d35.9 shows macro values as they are defined
- -d35.14 – Shows macro names being converted to integer id’s
- -d35.24 – Shows macro expansion
- -d37 – Traces options and class macros
- -d37.1 – Traces the setting of options
- -d37.8 – Traces the adding of words to a class
- -d41 – Traces the queue
- -d41.1 – Traces queue ordering
- -d41.2 – Shows failure to open qf files
- -d41.49 – Shows skipped queue files
- -d41.50 – Show every file in queue
Set senders full name
-f
Set senders address
-h
Set minimum hop count
-i
Set IgnoreDots option to true
-M
Set macro
-N
Set return DNS notify information
- never – Never return the info
- success – Return on successful delivery
- failure – Return on failure
- delay – Return on delayed delivery
Supresses aliasing
-O
Set an option (long name)
-o
Set an option (short name)
-pUUCP:test
Sets protocol in $r macro to UUCP and $s macro to test
-q30m
Sets queue processing to every 30 min
-qR@here.com
Processes the queue once delivering only mail to @here.com
-R hdrs
bounces only the headers
-R full
Bounces headers and body
-s
Sets SaveFromLine option to true
-T 5d
Sets Timeout.queuereturn option to 5 days
-t
Gathers a list of recipients from messages headers
-U
make this the initial MUA to MTA submission
-V test123456
Sets the DSN ENVID string to test123456
-v
Runs sendmail in verbose mode
-X /var/tmp/trace.mail
Logs both sides of smtp transactions to trace.mail file.
Rule Testing Mode (/usr/lib/sendmail –bt)
?
Prints help .
DrUUCP
Defines macro r as UUCP
=S5
Prints the contents of ruleset 5
=M
Displays list of delivery agents
${name}
Prints the value of macro name.
$=w
prints the contents of the class macro w
/mx here.com
Returns the MX records for here.com in the order they will be utilized
/parse foo
Parses the value of the address foo, returns the value of crackaddr(), and the final parsed address including the delivery agent.
/try local foo
Rewrites the address foo based on the rules for local delivery
/tryflags HS
Sets the flags used by /parse and /try to H for header and S for sender, can also use E for envelope and R for recipient
/canon foo
Transforms the hostname foo into its canonical form
/map aliases foo
Looks up foo in the aliases database
3,0 – me@foo
Runs the address me@foo through rulesets 3 and 0
Wednesday, September 30, 2009
SENDMAIL Notes 14: Sendmail SMTP AUTH
Sendmail SMTP AUTH
SMTP Auth support allows to relay mails based on the smtp authentication when the client or users IP is getting changed(For a Roaming user).
Inorder to enable the smtp-auth support in sendmail the following packages are needed.
- cyrus-sasl
- cyrus-sasl-plain (For Plain Authentication)
- cyrus-sasl-devel (Some devel libs are needed by sendmail)
- cyrus-sasl-crammd5 (For CRAM MD5 auth)
- cyrus-sasl-digestmd5
- cyrus-sasl-otp
- cyrus-sasl-gssapi
cyrus-libraries are needed for SMTP-AUTH. After installation the above packages the cyrus-libs will be installed in /usr/lib
Note:-
If the distribution is not supporting the cyrus package, then we have to download it compile with all the auth mechanism and install.
Now we need to compile the sendmail with cyrus and install the binaries.
Compiling & installing the sendmail for SMTP AUTH:
Got to the following directory
The Top Level Build Script (which creates the sendmail binaries) while compiling will consult the Site directory and if it finds the site.config.m4 it will include the contents for compiling. So this file is used to include additional variables or modules or extend the features sendmail. For enabling such features we have to include some derivatives in the site.config.m4.
To test the existing sendmail has SMTP-AUTH enabled:
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 centos.com ESMTP Sendmail 8.14.2/8.14.2; Thu, 1 Oct 2009 17:41:53 +0400
ehlo localhost
250-centos.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-DELIVERBY
250 HELP
The other way of testing the sendmail for the feature of SMTP-AUTH is
Now we will create some derivatives in the site.config.m4 file and compile & install sendmail again to enable the SMTP-AUTH in sendmail.
#This will tell sendmail to include the support sasl version 2
APPENDDEF(`conf_sendmail_LIBS', `-lsasl2')
#This will tell sendmail to use the given libraries that can be found in the lib directory as mentioned in the next derivative
APPENDDEF(`confLIBDIRS', `-L/usr/lib')
APPENDDEF(`conf_INCDIRS',`-I/usr/include/sasl')
#This will tell sendmail the location of the header files
# ./Build
Before copying the sendmail binary to /usr/sbin location we will check whether the new compiled binary has the the option of sendmail SMTP-AUTH
To check this navigate to following directory
# ./sendmail -v -d0.10
# chmod g+s /usr/sbin/sendmail
To verify
-r-xr-sr-x 1 root smmsp 678197 Oct 1 18:54 sendmail
Now configure the sendmail.mc file to include the smtp-auth
# vi sendmail.mc
TRUST_AUTH_MECH(`LOGIN PLAIN GSSAPI DIGEST-MD5')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN GSSAPI DIGEST-MD5')dnl
configuration auth mechanism tells sendmail that these are the authentication mechanisms that have been configured.
This will make sendmail to hands over the authentication to cyrus libs.
Note:-
Sendmail hands over the control to cyrus libraries for authentication. Cyrus-libs will check the passwd file or ldap for authentication.
# m4 ../m4/cf.m4 sendmail.mc > sendmail.cf
# cp sendmail.cf /etc/mail
# restart the sendmail service
Testing the SMTP-AUTH support is turned on
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 centos.com ESMTP Sendmail 8.14.2/8.14.2; Fri, 2 Oct 2009 17:18:57 +0400
ehlo localhost
250-centos.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-AUTH LOGIN PLAIN DIGEST-MD5
250-DELIVERBY
250 HELP
Here we are looking for the line "250-AUTH LOGIN PLAIN DIGEST-MD5"
Note:-
If this test fails even if all the configurations have been made correctly, troubleshoot the issue by rechecking configuration files and binaries time stamp as well use netstat command to verify that the sendmail process is bind to the port 25.
Now have to configure cyrus to accept the request of sendmail
# vi smtp.conf
or
# vim /etc/sasl2/sendmail.conf
pwcheck_method: saslauthd
We have to rename the smtp.conf to Sendmail.conf . In filename Sendmail.conf S is capital.
Now start the saslauthd service
Note:
If we are getting any errors like - AUTH failure (PLAIN): user not found (-20) SASL(-13): user not found: Password verification failed
Try uninstalling all the "cyrus" packages and reinstall one bye one will sort out the issues. It worked for me
Monday, September 28, 2009
SENDMAIL Notes 13: Sendmail Content Scanning
SENDMAIL CONTENT SCANNING:
Configuring the full functional content scanning using Mailscanner, Clamav and Spamassassin
Initially we will configure the clamav antivirus.
CLAMAV ANTIVIRUS:
Installation of CLAMAV Antivirus:
Download the Source code of the software
# wget http://sourceforge.net/projects/clamav/files/clamav/0.95.2/clamav-0.95.2.tar.gz/download
# tar -zxvf clamav-0.95.2.tar.gz
# cd clamav-0.95.2
1. zlibs It needs zlib-1.2.2 atleast
zlibs-devel
2. bzip2
bzip2-libs
bzip2-devel
3. gmp
4. curl
curl-devel
#groupadd clamav
#useradd -g clamav -s /sbin/nologin clamav
# ./configure
# make
# make install
Configuring CLAMAV Antivirus:
#cd /usr/loca/etc
For starting the clamd daemon, have to edit the following parameters in clamd.conf
#vim clamd.conf
#comment out the Example
#Example
#vim freshclam.conf
#comment out the Example
#Example
#touch /var/log/freshclam.log
#chmod 600 /var/log/freshclam.log
#chown clamav.clamav /var/log/freshclam.log
#freshclam
#/usr/loca/bin/freshclam -d
It is time to start the clamd daemon now.
#/usr/local/sbin/clamd
#ps -ef |grep clam
Adding clamd daemon to init startup(This part is optional).
#cd clamav-ver/contrib/init
#vim clamd
#cp clamd /etc/init.d
Now start configuring the Spamassassin
SPAMASSASSIN:
Installation:
Download the Source code of the software
# wget http://www.bizdirusa.com/mirrors/apache/spamassassin/source/Mail-SpamAssassin-3.2.5.tar.bz2
# tar -jxvf Mail-SpamAssassin-3.2.5.tar.bz2
# cd Mail-SpamAssassin-3.2.5
1. HTML::Parser
Install the pre-requiesties using cpanel.
#cpanel
>install HTML::Parser
Download from cpan.org and compile and install
#tar -zxvf HTML-Parser-version.gz
# cd HTML-Parser-version
# perl Makefile.pl
# make
# make install
#perl Makefile.PL
1.mail address of admin for whom can send mail about the spam report.
2.network test
3.Checks for all the dependencies of modules. if script exits by any failed dependencies install it.
# make
# make install
Now we can install the init scripts from the source code.
#cd Mail-SpamAssassin-3.2.5/spamd
# ./redhat-rc-script.sh start
Now start the spamd
# spamd -d -c -m5 -H
Its time to install and configure the Mailscanner
MAILSCANNER:
Installation:
mailscanner need not to have clamd or spamassassin running to initialize or run the service.In fact it just need the perl modules that required to start.
Download the source code of the software.
#wget http://www.mailscanner.info/files/4/tar/MailScanner-install-4.75.11-1.tar.gz
#tar -zxvf MailScanner-install-4.75.11-1.tar.gz
# cd MailScanner-install-4.75.11-1
it contains perl modules and install script
#./install.sh
/var/spool/MailScanner
This is a temperory directory userd for processing the msgs.
/var/spool/mqueue.in
port25 sendmail(1) recieves msg -> Place the msg in mqueue.in -> Mailscanner scans and places in mqueue -> sendmail(2) will deliver the msg from mqueue to destination.
Configuring MailScanner:
#cd /opt/MailScanner
This is a symbolic link created by for the installed version of MailScanner.
# cd /opt/MailScanner/etc
This file contains the main configuration of MailScanner.
# vi MailScanner.conf
%org-name% = kiranjith
%org-long-name% = Kiran's School for Linux Lovers
%web-site% = kiranjith83.blogspot.com
Max Children = 5
#by default mailscanner will launch upto 5 process to handle the mails in the mqueue.in. This can be increased according to the msg queue.
Run As User = root
# has to specify the mailscanner to run as.
Queue Scan Interval = 5
# this tells the mailscanner to check the mqueue.in directory in every 5 sec for a new msg.
Incoming Queue Dir = /var/spool/mqueue.in
#This is the directory where the 1st sendmail instance will put the incoming mails for scanning.
Outgoing Queue Dir = /var/spool/mqueue
#This is the directory where the mailscanner will place the scanned mails for 2nd instance of the sendmail to deliver.
Incoming Work Dir = /var/spool/MailScanner/incoming
#This is the directory where mailscanner process the msgs.
Quarantine Dir = /var/spool/MailScanner/quarantine
#In this directory MailScanner places the msgs which is infected by Virus.
Restart Every = 14400
#Every 14400 sec the child process will get restarted
MTA = sendmail
#This specifies the current mta running in the system.
Sendmail = /usr/lib/sendmail
#path to sendmail which used to deliver the error generated on scanning
Max Normal Queue Size = 800
# this tells mailscanner to stop scanning if the mail queue is this much big
#Note:- TNEF Module is needed to scan the content send from MS Outlook.
Virus Scanning = yes
# This enables the virus scanning
Virus Scanners = clamav
#sets the virus scanner to clamav.
Use SpamAssassin = yes
# makes mailscanner to invoke the spamassassin
Always Include SpamAssassin Repot = yes
#this invokes mailscanner to involve the result of spamassassin.
# The SpamAssassin returns a score for the scanned msg and mailscanner will make a decission upon this score. This will invoke both clamav and spamassassin.
Always Include SpamAssassin Report = yes
# This will include the spamassassin repot in the mail header.
/opt/MailScanner/spam.assassin.prefs.conf
/opt/MailScanner/virus.scanners.conf
/opt/MailScanner/mcp
/opt/MailScanner/bin
#./check_mailscanner
#ps -ef |grep -i mailscanner
Sendmail Integrating with MailScanner:
By default the sendmail will be running as MSP as queue directory /var/spool/cilentmqueue and as MTA that binds to the default port of 25.
#/usr/sbin/sendmail -L sm-msp-queue -Ac -q30m
#/usr/sbin/sendmail -L sm-mta -bd -q30m
#kill any existing sendmail deamons
#vim sendmail_startup.sh
#!/bin/bash
sendmail=/usr/sbin/sendmail
#Run the sendmail as MSP program.
$sendmail -L sm-msp-queue -Ac -q30m
#Run the sendmail MTA for inbound (To accept the mail and keep in /var/spool/mqueue.in directory in queueonly mode)
$sendmail -L sm-mta-inbound -bd -OprivacyOptions=noetrn -OdeliveryMode=queueonly -OqueueDirectory=/var/spool/mqueue.in -OPidFile=/var/run/sendmail-in.pid -q30m
#Define the Outbound MTA for delivery msg from /var/spool/mqueue directory,which has been scanned by and placed by MailScanner. The inervel should be short for delivering the mail ASAP.
$sendmail -q1m
Save and execute the script.
#ps -ef |grep sendmail
Check the mail logs
# tail /var/log/maillog
Change Commands That Start Sendmail. Currently, your copy of sendmail will be started by a script such as /etc/init.d/mail or /etc/rc.d/init.d/sendmail. Somewhere in this script will be the command to start sendmail itself. This should look like this:
---------------
sendmail −bd −q15m
--------------
You should change this to the following two lines:
-------------
sendmail −bd -OprivacyOptions=noetrn -OdeliveryMode=queueonly -OqueueDirectory=/var/spool/mqueue.in -OPidFile=/var/run/sendmail-in.pid -q30m
sendmail -q1m
-------------
Note:-
The spamd and clamd deamons are not needed to be running. It is just to ensure the configuration files working or not.
Sunday, September 27, 2009
SENDMAIL Notes 12: Sendmail Mailertable
It is a type of mail relaying. It is useful when using the virtual domains. for example if you want to forward mails to internal protected server in DMZ zone after the content scanning, mailertable can provide a solution rather than using the smarthost or nullclient.
Configuring the Mailer Table:
Configure the following in the server which is configured to recieve the mails through MX record.
Create the /etc/mail/mailertable
Left Column
domain name
(To which domian it accepts
the mail for)
Right Column
Routing Rules:
(Specify the mailer type(smtp or local):
user@domain or FQDN of host))
jithu.com smtp:jeo@mail1.jithu.com
For Example:
This used primarily in the following scenario.
We have the mailertable enabled server facing the internet configured with MX record and all the mail scanning softwares. And other servers will be inside the network. So the mailertable enabled server recieves the mail primarly, scans the mail and forwards to respective servers according to the configuration in mailertable. So all the mails for a domain can be accepted by a single system and after scanning the mails can be redirected to respective sub-domains.
Now create the db file of mailertable
Saturday, September 26, 2009
SENDMAIL Notes 11: Sendmail Virtual Domains & Vitual Users
Basic Virtual Domains
Sendmail allows to host multiple domains in single instance. The Basic Virtual Domain can be created using local-host-name file. When sendmail receives mail, it needs a way of determining whether it is responsible for the mail it receives. It uses the /etc/mail/local-host-names file to do this. This file has a list of hostnames and domains for which sendmail responsible for mail.
For example, if this mail server was to accept mail for the domains kiran.com and jithu.com then the file would look like this:
# cat /etc/mail/local-host-names
kiran.com
jithu.com
jithu.com. MX 10 mail.kiran.com.
Note:
The mail server will default acceptance of mail for its FQDN defined without the entry in local-host-names.
Virtual users and virtual domains:
This is defined using the virtual user table feature in sendmail configuration.The file used is virtusertable in /etc/mail. While defining the virtusertable the domain name should not exist in local-host-names.
The /etc/mail/virtusertable file contains a set of simple instructions on what to do with received mail. The first column lists the target email address and the second column lists the local user's mail box, a remote email address, or a mailing list entry in the /etc/aliases file to which the email should be forwarded.
If there is no match in the virtusertable file, sendmail checks for the full email address in the /etc/aliases file.
Defining the virtual domains and users (Keep in mind that the exact MX record has been added to respective domains):
FEATURE(`virtusertable')dnl
VIRTUSER_DOMAIN_FILE(`-o /etc/mail/virtuserdomain')dnl
VIRTUSER_DOMAIN_FILE(`-o /etc/mail/virtuserdomain') it looks up the various domains that supported by sendmail in this given path.
#compile configuration and restart the sendmail service
#edit /etc/mail/virtuserdomain
kiran.com
jithu.com
#create/edit /etc/mail/virtusertable
user1@kiran.com kiran@someotherdomain
user2@jithu.com jithu
#makemap hash virtusertable < virtusertable
#Now restart the sendmail service
Other options in virtusertable:
@fazi.com jithu
@jithuki.com kiran
@mydomain.com mailuser@remotedomain.com
Friday, September 25, 2009
SENDMAIL Notes 10: Sendmail SMARTHOST & Null Client
Sendmail Smart Host
Smarthost is a smtp server that forwards the non local mails to another server that has proper DNS resolution.
DEFINING THE SMARTHOST:
Define this derivative in the Host mail configuration where we have to forward the mail to another server.
define(`SMART_HOST', `192.168.1.30')
or
define(`SMART_HOST', `isp.mailserver.com')
#recompile the sendmail.cf and restart the sendmail service in hosts
Permit the host in Relay
#vi /etc/mail/access
add the ip address of the smarthost
#makemap hash acess < access
NULL CLIENT CONFIGURATION:
In contrast with SMARTHOST, NULL CLIENT CONFIGURATION will redirect all mails including local msgs, not just the remote mails to the defined server.This is used where in the situation that need to make the server to just send the msgs and not to receive any msgs.
Define the Following in the HOST that needed to be configured as NULL CLIENT.
first comment the SMART_HOST definition. Add the following in sendmail.mc
FEATURE(`nullclient', `isp.mailserver.com')
#recompile the sendmail.cf and restart the mail service
#sendmail -d -i
Now try sending msgs from host, this will make all the mail to relay through isp.mailserver.com.
Note:
As we are defining the Null client, since it is not setup to receive mail we have to make sure that the mail envelop will be re-written.Because in case of any reply or bouncing the host will not be accepting the mail.
SENDMAIL Notes 9: Sendmail Relay
Default configuration of the sendmail Denies the Relay from other hosts.
But the following option makes the sendmail to run as open relay
FEATURE(`promiscuous_relay')
Testing a Open relay:
Try to connect to the Server from outside of the network and follow the procedure.
The Following Example shows the server that denies the Open Relay:
[root@kiran ~]# telnet 192.168.10.2 25
Trying 192.168.10.2...
Connected to fazi.com (192.168.10.2).
Escape character is '^]'.
220 centos.com ESMTP Sendmail 8.14.2/8.14.2; Wed, 23 Sep 2009 06:35:20 +0400
Mail from: kiran@domain.com
250 2.1.0 kiran@domain.com... Sender ok
Rcpt To: kiran@anotherdomain.com
550 5.7.1 kiran@anotherdomain.com... Relaying denied
quit
221 2.0.0 centos.com closing connection
Connection closed by foreign host.
[root@kiran ~]#
[root@kiran ~]# telnet 192.168.10.2 25
Trying 192.168.10.2...
Connected to fazi.com (192.168.10.2).
Escape character is '^]'.
220 centos.com ESMTP Sendmail 8.14.2/8.14.2; Wed, 23 Sep 2009 06:43:14 +0400
Helo domain.com
250 centos.com Hello mail1.kiran.com [192.168.10.1], pleased to meet you
Mail From:kiran@domain.com
250 2.1.0 kiran@domain.com... Sender ok
Rcpt To:kiran@anydomain.com
250 2.1.5 kiran@anydomain.com... Recipient ok
Data
354 Enter mail, end with "." on a line by itself
This is to test the Open relay
.
250 2.0.0 n8N2hEOp009181 Message accepted for delivery
Quit
221 2.0.0 centos.com closing connection
Connection closed by foreign host.
[root@kiran ~]#
Relay in Sendmail:
Relay in sendmail can be achieved by 2 common ways
1. Using the Relay-domains.
2. Using the access database.
1. Using relay-domains file:
This is very easy way to implementing the relay access.
Edit sendmail.mc
RELAY_DOMAIN_FILE(`/etc/mail/relay-domains')
/etc/mail/relay-domains file can contain each IP Address of the hosts on each line (Hostname of FQDN is permissible here and this has to be resolved properly).
Example:-
192.168.1.1
10.0.0.1
172.16.0.1
Compile and Restart the sendmail service
RELAY_DOMAIN_FILE(`-o /etc/mail/relay-domains')
2. Using the Access DB:
It extends the functionality of relay domains, defined by two columns.
Left Hand Side Column:
Users
Hosts
Ip Address
Right hand Side Column:
Relay
Reject
Discard
To enable this have to turn on the following feature.
FEATURE(`access_db', `hash -o -T
Now Create the access_db file:
#vi /etc/mail/access
connect:192.168.1.2 RELAY
connect:192.168.10.9 REJECT
#makemap hash access < access
Here from the ip 192.168.1.2 sendmail will relay mail to outer world and from 192.168.10.9 will reject the relay to outer world This will make the sendmail to reject all the inbound mail traffic from the host 192.168.10.9.
Any update to the access doesn't need sendmail reload to take effect. Because for each query sendmail makes query to the access.db file.
Other rules in access file:
From:kiran@mail1.kiran.com REJECT
To:jithu@ RELAY
In To:jithu@ REJECT any mail send to user jithu will be REJECTED.
To parse this rule in access db file by sendmail we have to enable the following Macro Feature in the sendmail.cf file.
FEATURE(`relay_mail_from')
Now compile the sendmail.cf file and restart the service.
Monday, September 21, 2009
SENDMAIL Notes 8: Sendmail Macro File Derivatives
Derivatives in Sendmail.mc Configuration file:
#grep -i ^O sendmail.cf
Options & Features in sendmail.mc:
Editing the sendmail.mc file:
Any Options that enables inside the sendmai.mc or submit.mc should be specified after the DOMAIN(generic)dnl option
Any rules that defines should come after the MAILER option inside the sendmail.mc/submit.mc file
Increasing the verbositry of Log Level of sendmail:
Default level is 9.
define(`confLOG_LEVEL', `10')dnl
#./Build install-cf
or
#m4 ../m4/cf.m4 sendmail.mc > sendmail.cf
Restart the sendmail
# kill -HUP `head -1 /var/run/sendmail.pid`
Maximun msg size:
Default is undefined
define(`confMAX_MESSAGE_SIZE', `4096')dnl
Recompile the sendmail.cf file
Restart the sendmail service
Configuring the Maximum Recipients for MSG:
define(`confMAX_RCPTS_PER_MESSAGE', `1')dnl
Recompile the sendmail.cf file
Restart the sendmail
O MaxRecipientsPerMessage=1
": Too many recipients". The msgs are queued for later delivery
Masquerading in sendmail:
Masquerading changes the mail headers.A message header is the part of the message that contains information about a specific aspect of the message. This option should define prior to the mailer derivative.
MASQUERADE_AS(`mail1.jithu.com')
or
MASQUERADE_AS(`jithu.com')
For example:- mail send from host1.domain.com will be masqueraded as
From:- kiran@mail1.jithu.com
So if the recipient replies to msg will send to the host mail1.jithu.com
Masquerade the envelope:
This will masquerade the mail envelope.Envelope is what appears initially.The sender and recipient addresses used in the SMTP transaction are called the Message Envelope. In other words A message envelope is the structure that encapsulates the component parts of a message: the message body and the message headers.
FEATURE(`masquerade_envelope')
But the message coming from root will not be masqueraded as for other normal users.
Exposed users to exclude the masquerade:
This will exclude a given user from masquerading. root user is excluded by default from masquerading.
EXPOSED_USER(`jithu kiran joe paul')dnl
Or
EXPOSED_USER(`jithu')dnl
Or
EXPOSED_USER_LIST(`path to user list')dnl # user list should be one user per line
Enabling the mail server to relay mails from any where:
FEATURE(`promiscuous_relay')
#compile and restart the sendmail service
Masquerade Domains:
Default masquerading behavior of sendmail is, only masquerading the host part of the mail generated locally and it won't masquerade the mails that generated from other systems.So including the option of masquerade domains will masquerade the hostname part of the mail for all other hosts that sendmail relays.
FEATURE(`masquerade_entire_domain')
MASQUERADE_DOMAIN(`mail1.fazi.com')
This option is valid upon the position of FEATURE(`masquerade_entire_domain'), which masquerades entire mails send by any hosts.
If FEATURE(`masquerade_entire_domain') is set after MASQUERADE_AS(`jithu.com') then the undefined hosts will not be masqueraded.
Masquerading Options Explained:
FEATURE(always_add_domain)dnl
FEATURE(`masquerade_entire_domain')dnl
FEATURE(`masquerade_envelope')dnl
FEATURE(`allmasquerade')dnl
MASQUERADE_AS(`my-site.com')dnl
MASQUERADE_DOMAIN(`my-site.com.')dnl
MASQUERADE_DOMAIN(localhost)dnl
MASQUERADE_DOMAIN(localhost.localdomain)dnl
- The MASQUERADE_AS directive makes all mail originating on bigboy appear to come from a server within the domain my-site.com by rewriting the email header.
- The MASQUERADE_DOMAIN directive makes mail relayed via bigboy from all machines in the another-site.com and localdomain domains appear to come from the MASQUERADE_AS domain of my-site.com. Using DNS, sendmail checks the domain name associated with the IP address of the mail relay client sending the mail to help it determine whether it should do masquerading or not.
- FEATURE masquerade_entire_domain makes sendmail masquerade servers named *my-site.com, and *another-site.com as my-site.com. In other words, mail from sales.my-site.com would be masqueraded as my-site.com. If this wasn't selected, then only servers named my-site.com and my-othersite.com would be masqueraded. Use this with caution when you are sure you have the necessary authority to do this.
- FEATURE allmasquerade makes sendmail rewrite both recipient addresses and sender addresses relative to the local machine. If you cc: yourself on an outgoing mail, the other recipient sees a cc: to an address he knows instead of one on localhost.localdomain.
- FEATURE always_add_domain always masquerades email addresses, even if the mail is sent from a user on the mail server to another user on the same mail server.
- FEATURE masquerade_envelope rewrites the email envelope just as MASQUERADE_AS rewrote the header.

Sunday, September 20, 2009
SENDMAIL Notes 7: Sendmail Macros and Basic Configurations
M4 configuration in Sendmail
M4 is a Macro program which allows to define key value pairs i.e names with values, such as configuration options with values and responsible for expanding the values to syntax that sendmail that recognizes.
eg:- sendmail.mc(Human readable config file) file is the input taken by M4 to create sendmail.cf(sendmail readable) file.
Generation Of Sendmail Configuration Files:
If u are installing the sendmail from the source code all the configuration examples and M4 files that needed while converting the "*.mc" file will be present inside the directory /sendmail-8.14.2/cf. and if you are using the rpm based binaries all the configurations example and M4 files that needed while converting the "*.mc" file will be present inside /usr/share/sendmail-cf
The following is the basic configurations that needed by sendmail in sendmail.mc file to start with
divert(-1)
divert(0)dnl
VERSIONID(`$Id: generic-linux.mc,v 8.1 1999/09/24 22:48:05 gshapiro Exp $')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
MAILER(local)dnl
MAILER(smtp)dnl
/sendmail-8.14.2/cf or /usr/share/sendmail-cf directory:
m4/: directory contains the files that is used for compiling M4 with sendmail config file while running the Build script from the sub-directory cf/ (or #m4 sendmail.mc > sendmail.cf)
README.txt: file contains all the derivatives that can be understood ( M4 preprocessor )by sendmail inside this directory.
cf/: In /sendmail-8.14.2/cf or /usr/share/sendmail-cf "cf/" is the sub-directory which contains the M4 configuration files. generic-linux.mc & generic-linux.cf are the two config files that is used for generation of sendmail.cf file. These configuration file is enough to create a minimum level of sendmail server on Linux distros.
sendmail.mc file is used by MTA and submit.cf file is used by MSP.
Basic Derivatives and struchure of sendmail.mc:
dnl = delete through new line
This tells the M4 deamon to delete any superfluous or excessive new lines after creation of subsequent derivatives for mc files to cf file.
VERSIONID(`$Id: generic-linux.mc,v 8.1 1999/09/24 22:48:05 gshapiro Exp $')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
.forward file path
maximum mail Header Length.
use of cw file etc.
MAILER(local)dnl &
MAILER(smtp)dnl
Here every mailer has their own defnitions. inlcudes the path of program and the rules.
local mailer permits the redirection of the msgs in to programs.
Running
`./Build install-cf`
In source:
[root@centos cf]# pwd
/root/sendmail/sendmail-8.14.2/cf/cf
[root@centos cf]# m4 ../m4/cf.m4 sendmail.mc
#m4 sendmail.mc > sendmail.cf
SENDMAIL Notes 6: Sendmail with DNS FQDN & MX records
Remote mail involves the usage of SMTP thus sendmail needs the name resolution to route the mails. For this sendmail uses DNS or uses /etc/hosts.
Find the FQDN of a host
# hostname -f
Sendmail DNS Usage:
Using FQDN:
Sendmail performs the DNS lookup for the defined host address and gets the IP address and then delivers the msg to the destination.Remote hosts either accepts the mail or Routes the mail using any local mailer or Relays to another destination upon the configuration.
For example:
#sendmail -v kiran@mail1.india.mydomain.com
Using MX:
MX is a special type of DNS record called as Mail Exchanger Record.When mail server actualy query a Domain for direct mail, they query the dns server for the MX record and once found sendmail will attempt to direct the mail to destination according to the priority of MX record.
Normally an "A" record is enough to get the IP address of the host for sendmail to send the mail.But MX is used because to distinguish/identify the mail servers in the given domain
For Example:-
#sendmail -v kiran@mydomain.com
(So in nameserver the MX record entry for mail1.india is added to the domain mydomain.com; Make sure that we have a 'A' record created for the same MX record)
This means any the mail comes to kiran@mydomain.com will be routed to mail1.india.mydomain.com to process with.
Backup MX & Priority in MX:
mydomain.com. 14000 IN MX 20 mail2.india.mydomain.com.
mydomain.com. 14000 IN MX 10 mail1.india.mydomain.com.
If a backup MX server is running make sure that the user mail box is located in the backup mail server as well.
Wednesday, September 16, 2009
SENDMAIL Notes 5: Sendmail - Aliases
Aliases is used to handle mails to a non existing address. This will allow to redirect the msgs destined to a given name to a real user.
eg:-
postmaster: kiran@domain.com,jrkiran@domain.com
The Aliases File:
Default Aliases in system:
MAILER-DAEMON: postmaster
postmaster: root
i.e, if a mail is send to a non existing user then the mail header is modified to MAILER-DAEMON as user.
This means the problem msg or bounced msg has to go some where, and sendmail delivers it to MAILER-DAEMON.
MAILER-DAEMON is aliased to postmaster, and postmaster aliased to root - hence the mail is delivered to root.
Aliases File is case insensitive:
The aliases defined in sendmail is case insensitive.
After changing the aliases no need to restart or reload the sendmail service because in each and every request sendmail consults the db of aliases.
Types of aliases defined
There are 5 types of aliases:
1. 1-to-1 Aliases.(1 alias map to one local username)
eg:-
postmaster: root
bin: root
support: kiran
eg:-
info: kiran,jithu,rinz
sales: hr,joe,nick
This will allow aliases to include the list from separate file
eg:-
finance: :include:/full/path/to/list.list
4. File Redirection Aliases - Re-route the message to file
eg:-
abuse: root,/var/log/abuse/mail
help: /var/log/help
5.Redirecting the E-mail to PIPE (redirecting the output to an application)
when a mail comes we can send the output to certain commands. for example if mail comes for the user john and the is in vacation then we can redirect the mail to the program "vacation" to send the automated reply.
eg:-
kiran: "|/usr/bin/vacation kiran"
Add entry
#vim /etc/mail/aliase
support: kiran
#newaliases
#sendmail -bi
# sendmail -bv support
kiran... deliverable: mailer local, user kiran
Vacation Program
To enable the vacation program for an user called fazi install the vacation program that comes along with the sendmail binary.
Create a forward file
# vim ~/.forward
\fazi, "|/usr/bin/vacation -t0 fazi"
# vim ~/.vacation.msg
Hi Thanks for you mail !
hai i am on vacation
will ping you once i'm back
SENDMAIL Notes 4 : Sendmail Logs Analyze
#grep -i mail /etc/syslog.conf
# Log anything (except mail) of level info or higher.
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# Log all the mail messages in one place.
mail.* ; -/var/log/maillog
#facility.severity destination
severity = info,err,warn,debug
destination = /var/log/messages, /var/log/maillog
/var/log/messages will be logged other than all mail logs, i.e no maillogs will be logged to /var/log/messages and /var/log/maillog will be logged with all the mail activities.
To log the mail activities separately use the following option in /etc/syslog.conf
mail.* -/var/log/mail
mail.info -/var/log/mail.info
mail.warning -/var/log/mail.warn
mail.err -/var/log/mail.err
MailLog format:
Ack Log for msg received in MTA:
Sep 13 09:08:36 centos sendmail[6265]: n8D58YWM006265: from=
Daily Time stamp: message came from server: Daemon: Process ID: queue ID: From Server: size of message: class: number of recipient: msg id: relay=root@localhost (who has send the message from which host)
MSG Delivery Log:
Sep 13 09:08:36 centos sendmail[6268]: n8D58YWM006265: to=
Time stamp:hostname:daemon:PID:queue ID: to=recipient:ctladdr=is the local user who sends the msg (ctladdr user ID /& Group ID):delay=is expressed the amount of time between the msg recieved and delivered:xdelay=amount of time taken to transfer the msg (from user to user or host to host):mailer=the type of the mailer used in sendmail:pri=priority:dsn= Delivery Status Notification(Email Delivery Error Codes ):status=status of msg delivery
How many times you got your outgoing emails back and wondered what is wrong with it? Every time when your email can not be delivered, the SMTP server sends you a notification, which includes a standard error message, associated with the real problem.
Each code is composed of three digits (X.X.X). The first digit gives the status of the email message:
Here is a complete list of email delivery error codes, based on the Extended SMTP (ESMTP) standards, where X can be 4 or 5, depending on the error type (Persistent Transient or Permanent):
|
For checking the mail log - Better to grep the queue id from maillog to check the msg status:
# grep queueid /var/log/maillog
# grep "Aug 15" /var/log/maillog