dropdown menu

NETWORK - SENDMAIL

Sendmail

The sendmail command receives formatted text messages and routes the messages to one or more users.

/etc/mail/sendmail.cf   sendmail configurations, after modifications refresh -s sendmail
/var/spool/mqueue       mail queue, stores data and control files for messages (can store temporarily the mail here)
                        (if the mail queue becomes unresponsive run: sendmail -q -v (-q: force the queue to run, -v: verbose))
/usr/spool/mqueue       sendmail default logs are here (this is used, unless in syslog other dir is specified for mails)
/var/spool/mail/<user>  the user's mailbox resides here


----------------------------------------------------

Configuring sendmail:

1. starting sendmail
lssrc -s sendmail                                           <--checking if it is runnig
startsrc -s sendmail -a "-bd -q30m"                         <--starting if it is needed (-bd: background, q30: queue processing interval)
vi /etc/rc.tcpip -> uncomment: start /usr/lib/sendmail      <--sendmail is started from this file after reboot


2. set mail relay server
vi /etc/mail/sendmail.cf
#DSmailer:relayhostname
DSaix1.domain.com                                            <--at DS line set a smarthost (probably an SMTP server) which can forward mails

3. refresh sendmail
refresh -s sendmail                                          <--refresh sendmail to activate new settings

4. testing sendmail


-with mail command (sender mailbox can't be set):
echo "This is a test mail"|mail -v -s "this is the subject" mail_address@anything.com
(if this does not work maybe your sender mailbox (e.g. root@hostname) is not accepted by mail relay server)
(sender mailbox cannot be set with mail command and it will show as an accepted message, but mail won't be forwarded)


-with telnet (sender mailbox is possible to set):
On aixmail we have set a working mailrelay, and we test this from aixdb2:
(doing telnet on aixmail to localhost works as well)

root@aixdb2: / # telnet aixmail 25                           <--telnet to port 25
Trying...
Connected to aixmail.fsc.uk.
Escape character is '^]'.
220 aixmail.fsc.uk ESMTP Sendmail Thu, 3 Nov 2011 15:45:05 GMT
helo aixmail                                                <--saying hello to mailserver (setting up the communication,'ehlo' works as well)
250 aixmail.fsc.uk Hello aixdb2.fsc.uk [10.200.200.22], pleased to meet you
mail from: something@anything.com                          <--sets sender mailbox (don't forget on mailrelay could be some restricions)
250 2.1.0 something@anything.com... Sender ok              (if "Bad sender address syntax", use <> at address, i.e. <something@ganything.com>
rcpt to: mail_address@anything.com                         <--setting up the destination address
250 2.1.5 mail_address@anything.com... Recipient ok
data                                                       <--after this the subject and the body of the mail will follow
354 Enter mail, end with "." on a line by itself
subject: test message                                      <--subject
this is a test message from aixdb2                         <--mail body
                                                         <--end your mail with a "."
250 2.0.0 pA3Fj5mf586210 Message accepted for delivery
quit                                                       <--closes connection
221 2.0.0 aixmail.fsc.uk closing connection
Connection closed.

----------------------------------------------------

CONFIGURATION HINTS for sendmail.cf file:
(after manipulating sendmail.cf don't forget refresh -s sendmail)

-MAILRELAY CONFIG:
Mailrelay (Smart relay host) can be set at DS line:

# "Smart" relay host (may be null)
DSmailrelaynew.domain.com
#DSmailrelayold.domain.com


----------

-DOMAIN REWRITING:
If you want all mails are being sent from a specific domain
(only domain name will be rewritten, user name won't be changed)

I added the needed domain at 2 places in config file:
at Dj line:
Djservices.domain.com

and at DM line:
# who I masquerade as (null for no masquerading)
DMservices.domain.com

(At the mailserver where you send the mails there can be restricions, which sender domains are accepted.)

----------

-USER and DOMAIN REWRITING:
If you want all mails are being sent from a given sender address (user and domain will be rewritten: user@domain)

Find the below section at SMTP Mailrelay specification part and I commented out (put #) at all the lines, except SEnvFromSMTP.
I added one more line at the end which contains the sender mail address.
(it is important to use tab for spacing!)

#####################################
###   SMTP Mailer specification   ###
#####################################

...
...
...


#
#  envelope sender rewriting
#
SEnvFromSMTP=11
#R$+                    $: $>PseudoToReal $1            sender/recipient common
#R$* :; <@>             $@                              list:; special case
#R$*                    $: $>MasqSMTP $1                qualify unqual'ed names
#R$+                    $: $>MasqEnv $1                 do masquerading
R$*                     $: user1@anydomain.com        do mask

(details on why you see different sender address in your mail program: http://utcc.utoronto.ca/usg/technotes/smtp-intro.html)

----------------------------------------------------

These can be checked when there are problems:

- var/spool and /var/spool/mqueue group write rights may be needed


- lssrc -s sendmail (or ps -ef sendmail)


- lssrc -ls sendmail or mailstats
    root@aix20: /root # lssrc -ls sendmail
    Statistics from Tue Dec  7 12:05:47 2010
     M   msgsfr  bytes_from   msgsto    bytes_to  msgsrej msgsdis msgsqur  Mailer
     3        8          8K     1054     110084K        0       0       0  local
     4        0          0K        8          8K        0       0       0  smtp
    =====================================================================
     T        8          8K     1062     110092K        0       0       0
     C        0                    8                    0   

    msgsto: how many mail has been sent
    bytes_to: the size of all the sent messages
    msgsrej: messgaes rejected
    msgsdis: messages discarded

    local: sent mails to local users to /var/spool/mail/<user>
    smtp: sent mail to other hosts


- mailq
     it will show if mailq is processed or not
   
    root@aix20: /root # mailq
                /var/spool/mqueue (1 request)
    ----Q-ID---- --Size-- -----Q-Time----- ------------Sender/Recipient------------
    oB7AY7Qp909566       37 Tue Dec  7 11:34 root
                 (Deferred: local mailer (/bin/bellmail) exited with EX_TEMPFA)
                                         root
                Total requests: 1

    (It shows there are some problems as mailq is not processes, if it shows empty that is good)


- sendmail -v -q
    manually tests sendmail

    root@aix20: /root # sendmail -v -q
    Running /var/spool/mqueue/oB7AY7Qp909566 (sequence 1 of 1)
    root... Connecting to local...
    root... Deferred: local mailer (/bin/bellmail) exited with EX_TEMPFAIL

    (It shows there are some problems, if we receive no output, that would be good.)

- grep mail /etc/syslog.conf
    check syslog settings (if no mail line, then default line is valid for mail logs)
    mail.debug           /usr/spool/mqueue/syslog rotate size 1000k files 4


- sending a testmail (with mail or telnet)

----------------------------------------------------

Basic mail server config with sendmail

0. # vi /etc/mail/sendmail.cf

1. Fw/etc/mail/local-host-names        <--uncomment local-host-names, it defines which domains the mail server will be responsible for.

2. FR-o /etc/mail/relay-domains        <--uncomment relay-domains, it defines which hosts are allowed to use this server as a mail relay.

3. DSmailserver.domain.com             <--set "Smart" relay host if needed (may be null)

If the mail server is behind a firewall, you will need port 25 open. Typically a mail server has direct access through the firewall. But if the mail server does not have direct access through the firewall, then it will need to point to another mail server that can. In this case the admin can append the hostname of the mail server after the "DS".

4. create /etc/mail/local-host-names database file

# vi /etc/mail/local-host-names
   examples:
   testdomain.com                      <--it contains all the domains that this mail server will be accepting mail for.
   somedomain.com

5. create /etc/mail/relay-domains database file

# vi /etc/mail/relay-domains
   examples:
   testsystem                          <--it contains all the hostnames, subnets or domains that will be allowed to use this server as a mail relay.
   testdomain.com
   10.1.1.1
   192.168

6. stopsrc -s sendmail                  <--stop sendmail
7. startsrc -s sendmail -a "-bd -q30m"    <--start sendmail

----------------------------------------------------

Warning: .cf file is out of date: sendmail AIX5.3/8.13.4 supports version 10, .cf file is version 9
root@aix20: /root # sendmail -v -q
Warning: .cf file is out of date: sendmail AIX5.3/8.13.4 supports version 10, .cf file is version 9
   
change V9 to V10 in sendmail.cf:
root@aix20: /root # vi /etc/mail/sendmail.cf
# level 9 config file format
V10/Berkeley

----------------------------------------------------

mailstats: /etc/mail/statistics: No such file or directory

root@aixdb1: / # lssrc -ls sendmail
mailstats: /etc/mail/statistics: No such file or directory

root@aixdb1: / # touch /etc/mail/statistics

----------------------------------------------------

HOW TO CLEAR MAILS:
    1. mail             shows the user's mails
    2. d 1-1326         deletes the user's mail form the first to the 1326th
    3. h                shows the headers of the mails (or the remainders if we deleted some)
    4. q                quits

----------------------------------------------------

Deferred: local mailer (/bin/bellmail) exited with EX_TEMPFA

solution: http://aixblogs.blogspot.com/2009_04_01_archive.html

check permissions of /var/spool/mail and /var/spool/mqueue
!!!check also /var/spool


these are good settings:
root@aix20: /root # ls -ld /var/spool/mail
drwxrwxr-x    2 bin      mail            256 Dec 07 12:45 /var/spool/mail
root@aix20: /root # ls -ld /var/spool/mqueue

drwxrwx---    2 root     system         4096 Dec 07 12:45 /var/spool/mqueue

root@aix20: /root # ls -ld /var/spool
drwxrwxr-x   12 bin      bin            4096 Dec 07 12:46 /var/spool

----------------------------------------------------

gethostbyaddr(IPv6:::1) failed: 1

In syslog sendmail can log this warning message: "gethostbyaddr(IPv6:::1) failed: 1"

This is because IPv6 is enabled, and sendmail tries to do an IPv6 lookup on the IPv6 loopback interface (::1). This lookup is failing and the gethostbyaddr warning is logged by syslogd.

1. add ::1 loopback to /etc/hosts
root@aix20: /root # vi /etc/hosts
::1 loopback localhost


(Future releases of AIX will automatically include this entry in the /etc/hosts file)

2.add bind4 to /etc/netsvc.conf:
hosts=local,bind4

37 comments:

Anonymous said...

This is the best "quick sheet" I can find for every day UNIX system administration.

I use this information almost daily.

aix said...

Thank you for your feedback :)

baski said...

All about sendmail for an AIX admin, fantastic work.

aix said...

:)

Gabriel said...

Hi,

I have this weird issue that my AIX 6.1 does NOT have a SMTP server configured anywhere in sendmail.cf, but I am still able to send mail using "mail".

Are there any other config files that I can search in order to find out why the system is able to successfully deliver mail?

Thanks

aix said...

Hi,
I can't tell you a definite answer, only my assumptions. Mail command can be used to send mail to another user on the server locally, however if you would like to send to outside your server somehow should be aware the outside world. For example if your server is in the same domain as your DNS server or your /etc/hosts file has been setup very thoroughly, probably you are able to send mails without configuring sendmail.cf.
Thes are my assumptions only, probably someone else can help you out with a better answer.

Mandy said...

Hi Team,

I have configures send mail in Aix 6.1 ,

Updated sendmail.cf ---. DSdomainhostname.com
/etc/netsvc.com ---> "hosts = local, bind4"

/etc/resolv.conf ---> domain domain.com
nameserver x.x.x.x

when i try to send mail i got below error , mail is in queued state ,

mailq output

q9PAxQ3G54985190 2744 Thu Oct 25 16:29 aixadmin
(host map: lookup (pragathibank.com): deferred)
aix.fms@pragathibank.com
q9PB7csk30999052 2761 Thu Oct 25 16:37 aixadmin
(host map: lookup (pragathibank.com): deferred)
aix.fms@pragathibank.com

aix said...

Hi,

have you tried to restart sendmail after the modifications? If you do a "mail -v user@address" it will report back what error sendmail is encountering. (-v is verbose).
Can be resolved your domain correctly by nslookup?

Regards,
Balazs

newsfromhungary said...

Just do what I'm doing in such cases: 'truss' the mail process :)

Sendmail does work in 'standalone' mode as well. If syslog is configured properly, mail delivery can be tracked down in syslog.

newsfromhungary said...

> vi /etc/rc.tcpip

I recommend 'chrctcp -Sd sendmail' for disabling it to make sure smitty etc can handle the comment properly later on.

aix said...

Yes, that method is more secure, thx :)

Anonymous said...

Really excellent blog - thanks for sharing!

aix said...

Happy to hear that :)

Anonymous said...

In case user names with upper case letters are used you need to change the /etc/sendmail.cf . Otherwise the mail does not get delivered. 9 All from memory )

Enable support for uppercase user names - Change: Mlocal, .... sDFMAw5 to Mlocal, .... sDFMAw5u

Note the lowercase "u"
Example:
From
Mlocal, P=/bin/bellmail, F=lsDFMAw5:/|@qmn9, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,
to
Mlocal, P=/bin/bellmail, F=lsDFMAw5u:/|@qmn9, S=EnvFromL/HdrFromL, R=EnvToL/HdrToL,

aix said...

I didn't know that, thx :)

Anonymous said...

Hi, is it possible to send mail outside without SMTP relay server?

aix said...

I am not aware of this kind of setup....

Unknown said...

Thanks for your site! As trying to learn AIX as I go, this site I keep coming back to.

Unknown said...

hi,

i am able to send emails using sendmail, but unable to view the mailq. Not sure why..

when i type mailq at prompt, it doesnt do anything, doesnt even return to prompt. Any place where we have to configure /var/spool/mqueue as default mail directory?

Thanks

Cheap 1300 Number said...

Email servers are very important in terms of communication.

Bala said...

ur blog is execellent
have a doubt in send mai l

sendmail -t -F 'bala' -f 'mailid' << test.mail
From: mailid
To: mailid
Subject:test mail from server
Hi,

test mail sent from server


Regards
Bala

if i execute this scrpit like sh mail..sh. it works ..but if use mail or sendmail cmd i am not receiving any mail
echo "test" | sendmail mailid . i can see no work but i am not receving any mail ...but when excute above script like sh mail.sh i am receive mails any idea :)

Anonymous said...

Hi,

Can you please give me some idea on " how to block the incoming emails on AIX Server "


sendmail configuration on my AIX LPARs are working fine. I can get email notifications from AIX server. But i would like to restrict the incoming email (mail receipt) from out side to my AIX server.

please suggest.

Anonymous said...

Hi,
compliments for this quick sheet, so useful and clear!
My question is: is it possible to set multiple relayhost on sendmail.cf?

e.g DSrelayhost1:relayhost2

A sort of failover, cause in my company mx often are rebooted by other colleagues..and I lose my system alarms..
Thank you

Sridhar said...

Is it possible to set both SMTP/POP3 mail services on same AIX 6.1 ??? Can some one provide me the steps please... as we are looking on to create two dedicated LPAR for Inbound/Outbound on P7 frame and have both SMTP/POP3 mail services on same LPAR, use exiting Postfix V2.2.8 open source software and enable POP3 mail server alone to receive Bounce Mails. The Bounce back mail traffic size is less then 50 mails per Month..

Note : Our Exiting SMTP server running on AIX 5.3 and POP server running on Windows..

Anonymous said...

My AIX can send email to abc.com but cannot send to abc.com.mo for example even I put the correct domain IP in /etc/hosts. May you help for sendmail.cf in this case?

Anonymous said...

I really appreciate your efforts.

could you please tell me ,how can I disable or hide Mail Header Display.

thank you in advance...

Unknown said...

bin lookup In today’s electronic world, lot of transactions is performed online over the internet platform which poses a great risk on fraud transactions

Ameer said...

I need to prepare a script to house keep the mailbox for oracle.
The requirement:
1. To review house keep of mailbox based on size
2. or setup reasonable retention period

Anyone here can help me? Thank you in advance.

AK said...

i know its crazy but anybody uses sendmail with tls user and password authentication by any chance?

Anonymous said...

Hello,
I have the /var FS full because the directory /var/spool is 8GB. Can you help me
I need to know where can I configure the log rotare for the files on the directories /var/log/spool/mail and /var/log/spool/mqueue.

Thanks for your help

aix said...

Hello, probably you could check the /etc/syslog.conf file.

gantoki said...

I need to do that configuration please let me know if you have steps already

aix said...

I have no steps about that, maybe someone else...

gantoki said...

okey thanks

gantoki said...

any idea about installing postfix on AIX

Anonymous said...

How can config Sendmail with user/password?

Anonymous said...

you need to have version 7.3 and sendmail works with auth