News, tips, partners, and perspectives for the Oracle Solaris operating system


Guest Author

Entire books are written on sendmail, the popular e-mail transport agent for Unix and Linux. My goal here is to simply outline some of the specifics of using it with regards to OpenSolaris.

Personally, all I'm interested in is sending mail, not hosting a mail server, and this is how sendmail on OpenSolaris is configured by default. Looking at the sendmail service:

bleonard@os200906:~$ svcs -lp sendmail
fmri svc:/network/smtp:sendmail
name sendmail SMTP mail transfer agent
enabled true
state online
next_state none
state_time Fri May 21 12:05:39 2010
logfile /var/svc/log/network-smtp:sendmail.log
restarter svc:/system/svc/restarter:default
contract_id 102
dependency require_all/refresh file://localhost/etc/mail/sendmail.cf (online)
dependency require_all/refresh file://localhost/etc/nsswitch.conf (online)
dependency optional_all/none svc:/system/filesystem/autofs (online)
dependency require_all/none svc:/system/filesystem/local (online)
dependency require_all/none svc:/network/service (online)
dependency require_all/refresh svc:/milestone/name-services (online)
dependency optional_all/refresh svc:/system/identity:domain (online)
dependency optional_all/none svc:/system/system-log (online)
process 1121 /usr/lib/sendmail -bl -q15m
process 1122 /usr/lib/sendmail -bl -q15m

The -bl option instructs sendmail to only accept connections from the localhost.

You can send mail to yourself (more typically done by an application) or to another user on the host by using the mailx client and addressing it to <username>@<hostname>. For example:

bleonard@os200906:~$ mailx bleonard@os200906
Subject: Hello
Sending mail to myself.

Note, terminate the mail message using control+d.

The next time the user with mail logs into the machine they will be notified:

bleonard@os200906:~$ pfexec su - bleonard
Sun Microsystems Inc.

SunOS 5.11


November 2008
You have new mail.

And to read mail simply run mailx:

bleonard@os200906:~$ mailx
mailx version 5.0 Type ? for help.
"/var/mail/bleonard": 1 message 1 new
>N 1 Brian Leonard Fri May 21 12:18 17/672 Hello
? 1
Message 1:
From bleonard@os200906.local Fri May 21 12:18:09 2010
Date: Fri, 21 May 2010 12:18:09 -0400 (EDT)
From: Brian Leonard <bleonard@os200906.local>
To: bleonard@os200906.local
Subject: Hello
Sending mail to myself.
? quit
Saved 1 message in /export/home/bleonard/mbox

The messages are saved in simple text file which can be deleted if you don't want to delete them using the mailx client.

Sending mail to other hosts can be a bit more tricky, as mail servers have various criteria as to what they'll accept (mostly for anti-spam reasons). For example:

bleonard@os200906:~$ mailx william.leonard@oracle.com
Subject: Mail to Oracle account
Hi from OpenSolaris.

All looks well, until I check my mail:

bleonard@os200906:~$ mailx
mailx version 5.0 Type ? for help.
"/var/mail/bleonard": 1 message 1 new
>N 1 Mail Delivery Subs Fri May 21 12:32 69/2610 Returned mail: see transc

Reading the email I'll find the following:

   ----- The following addresses had permanent fatal errors -----
(reason: 553 5.1.8 <william.leonard@oracle.com>... Domain of sender address bleonard@os200906.local does not exist

Which is true, the mail server at Oracle has no idea what os200906.local is. The easiest way to get around this is to pass in a valid return address to mailx from which the Oracle mail server can resolve the host:

bleonard@os200906:~$ mailx -r william.leonard@oracle.com william.leonard@oracle.com
Subject: With Return Address
Hello from OpenSolaris.

Alternatively, you can set a proper hostname. To find your hostname use dig to do a reverse lookup on your IP address:

bleonard@os200906s:~$ dig -x
; <<>> DiG 9.3.6-P1 <<>> -x
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1051
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 6




;; Query time: 90 msec
;; WHEN: Fri May 21 12:57:13 2010
;; MSG SIZE rcvd: 357


bleonard@os200906:~$ pfexec hostname vpn-129-150-80-158.East.Sun.COM
bleonard@vpn-129-150-80-158.East.Sun.COM:~$ mailx william.leonard@oracle.com
Subject: Using Resolvable Hostname
Hello from OpenSolaris.

A helpful option for the mailx client is the verbose option,which will also indicate if there were errors in the transmission:

bleonard@os200906:~$ mailx -v william.leonard@oracle.com
Subject: Unresolvable Hostname
Hello from OpenSolaris.
bleonard@os200906:~$ william.leonard@oracle.com... Connecting to [] via relay...
220 os200906.local ESMTP Sendmail 8.14.3+Sun/8.14.3; Fri, 21 May 2010 13:52:49 -0400 (EDT)
>>> EHLO os200906.local
250-os200906.local Hello os200906 [], pleased to meet you
050 250 HELP
050 >>> MAIL From:<bleonard@os200906.local> SIZE=405
050 250 2.1.0 <bleonard@os200906.local>... Sender ok
050 >>> RCPT To:<william.leonard@oracle.com>
050 >>> DATA
050 553 5.1.8 <william.leonard@oracle.com>... Domain of sender address bleonard@os200906.local does not exist
050 503 5.0.0 Need RCPT (recipient)
050 >>> RSET
050 250 2.0.0 Reset state
050 <bleonard@os200906.local>... Connecting to local...
050 220 os200906 LMTP ready
050 >>> LHLO os200906.local
050 250-os200906
050 250-8BITMIME
050 >>> MAIL From:<>
050 250 2.5.0 ok
050 >>> RCPT To:<bleonard>
050 >>> DATA
050 250 2.1.5 ok
050 354 go ahead
050 >>> .
050 250 2.1.5 bleonard OK
050 <bleonard@os200906.local>... Sent
250 2.0.0 o4LHqns1000801 Message accepted for delivery
william.leonard@oracle.com... Sent (o4LHqns1000801 Message accepted for delivery)
Closing connection to []
>>> QUIT
221 2.0.0 os200906.local closing connection

Configuring sendmail

sendmail is customized by editing a configuration file (sendmail.mc) and compiling it into another configuration file (sendmail.cf). This article Configuring Sendmail on the Solaris 9 Platform is still relevant to OpenSolaris. This Sendmail Configuration Files document does a great job at explaining the options as does the README file you'll find at /etc/mail/cf/README.

As an example, let's configure the server so that it can redirect mail:

bleonard@os200906:/etc/mail/cf/cf$ pfexec chmod +w sendmail.mc

Edit sendmail.mc and insert the following line in bold. Note the parameter is opened with a back-quote (`) and closed with a single-quote ('):

define(`confFALLBACK_SMARTHOST', `mailhost$?m.$m$.')dnl

Then make the new sendmail.cf file:

bleonard@os200906:/etc/mail/cf/cf$ pfexec make sendmail.cf
test ! -f sendmail.cf || /usr/bin/mv sendmail.cf sendmail.cf.prev
/usr/ccs/bin/m4 ../m4/cf.m4 sendmail.mc > sendmail.cf

Then copy sendmail.cf to /etc/mail:

bleonard@os200906:/etc/mail/cf/cf$ pfexec cp sendmail.cf ../../.

The redirects are defined in the /etc/aliases file. So, for example, if I wanted to redirect all mail to brian to bleonard, I would simply add the following entry to /etc/aliases:


And compile the aliases file:

bleonard@os200906:/etc/mail$ pfexec newaliases
/etc/mail/aliases: 13 aliases, longest 10 bytes, 151 bytes total

And test:

bleonard@os200906:/etc/mail$ mailx -v brian@os200906
Subject: Mail to Brian
Hi Brian.
bleonard@os200906:/etc/mail$ brian... Connecting to [] via relay...
220 os200906.local ESMTP Sendmail 8.14.3+Sun/8.14.3; Fri, 21 May 2010 16:19:46 -0400 (EDT)
>>> EHLO os200906.local
250-os200906.local Hello os200906 [], pleased to meet you
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<bleonard@os200906.local> SIZE=63
250 2.1.0 <bleonard@os200906.local>... Sender ok
>>> RCPT To:<brian@os200906.local>
>>> DATA
050 <brian@os200906.local>... aliased to bleonard
250 2.1.5 <brian@os200906.local>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .


As I said, sendmail's a big beast, but I did find these resources helpful:

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha