Operating System - Linux
1827855 Members
1642 Online
109969 Solutions
New Discussion

Re: mailx not available, does sendmail have easy sending option?

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

mailx not available, does sendmail have easy sending option?

I have several linux systems that don't have mailx installed. Rather than install that package, is there some way to call sendmail within a shell script to send out a simple email with a subject line and no message body?
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: mailx not available, does sendmail have easy sending option?

Shalom Debbie

mail -s

Works just like mailx from hpus

mail -s "Subject is this" mail@mynetwork.com

Done.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Debbie Fleith
Regular Advisor

Re: mailx not available, does sendmail have easy sending option?

So, I have to code a separate "done" command to finish the mail, or is there some work around for a one-liner command to send a subject-only email?
Debbie Fleith
Regular Advisor

Re: mailx not available, does sendmail have easy sending option?

THe reason I asked about a one-liner without "done" is because when I try the mail -s command as you stated, it just hangs. Do I have some mail config problem?
Ken Grabowski
Respected Contributor

Re: mailx not available, does sendmail have easy sending option?

Hi Debbie,

This worked without a problem for me:
echo "test text string" | mail -s "Subject" my.address@myhost.com

No extra entry was required.
Steven E. Protter
Exalted Contributor

Re: mailx not available, does sendmail have easy sending option?

Yes Debbie, its exactly like you'd expect with HP-UX or Unix except mail -s instead of mailx.

I've gotten to the point where I create alias for mailx on Linux, but that doesn't help with cron jobs.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Stuart Browne
Honored Contributor
Solution

Re: mailx not available, does sendmail have easy sending option?

Make a Symlink SEP :)

But yes. 'mail' is an inline mailbox tool, which can send mail etc..

If you invoke it as just:

mail -s "This is the subject" recipient@domain

It will take you into an input mode, waiting for you to type the message body (before ^D/EOFing the input stream).

So you have to pipe something into it, or through it. So either the 'echo' example above, or something like:

mail -s "This is an empty message" recipient@domain < /dev/null

To close off STDIN. Of course, you can make the 'mail' the output pipe of some other string of commands, i.e.:

grep -Ei "error|warning" /var/log/messages | mail -s "Logged errors" recipient@domain

but that's entirely up to you.

As with 'mailx', the exit-code from mail states whether the message was successfully submitted to the local MTA.
One long-haired git at your service...