Showing results for 
Search instead for 
Did you mean: 

Mailx Doubt RHEL


Mailx Doubt RHEL

Hi we have a new Linux server with RHEL 4. Previously in HP UX we used -r option to sned mails via script to specify a from address. In Linux we dont have the -r option now can any one please help?
Steven E. Protter
Exalted Contributor

Re: Mailx Doubt RHEL


You con't even really have mailx. The command on Linux is mail but the man page is different.

I think you need to RTFM here but -s or -u looks good to me.

Steven E Protter
Owner of ISN Corporation
Ralph Grothe
Honored Contributor

Re: Mailx Doubt RHEL

Hi vinay,

that's true for RHEL's mail(x) command.

Btw, on my RHEL 5 boxes mailx is simply a symlink to mail, so you ought to be able to use the command name that you prefer (or rather may have carried over from scripts for other Unices).

There are several workarounds to forge the SMTP envelope's Return-path, even when using the mail(x) version without the -r option.

If you studied the manpage of mail(x) on you RHEL you may probably have noticed that you can pass additional sendmail options to the mail(x) command if they follow a double hyphen (i.e. all following that is regarded to be passed to the underlying sendmail).

That's fine since sendmail knows of the -f option (see man sendmail) by which you can specify a deviating Return-path address.
However, there is a little grain of salt,
if the invoker is any non-privileged user (viz. !root) and is not the same as that stated in the forged From address then sendmail will add an X-Authentication-Warning to your mails header.

Nevertheless, here's is how it should work.

$ echo "something to fill the body" | mail -s "any subject you like" recipient@their-maildomain.tld -- -fsender@other-than-login.tld

Besides this way, some claim that often a set environment variable of SENDER should also do the trick.
However, that hasn't worked for me.
Sould it work though, the invocation should be something like

$ echo "something to fill the body" | SENDER=sender@other-than-login.tld mail -s "any subject you like" recipient@their-maildomain.tld

Alternatively, you could avoid the usage of mail(x) altogether and script your own SMTP client (e.g. Perl's Net::SMTP or Mail::Mailer etc.)
Or you pipe your message directly into sendmail like


printf "From: %s\nSubject: %s\n\n" $(id -nu)@$(hostname) "any subject you like" "something to fill the body" | /usr/sbin/sendmail -ODeliveryMode=b -fsender@other-than-login.tld recipient@their-maildomain.tld

Instead of using printf you could also use a here-file sort of "redirection" to keep the command lines shorter.
Madness, thy name is system administration