Need to set mailx variable to specify the From address

4

Running Oracle Linux 5.8 (which is just re-branded RedHat EL 5.8) I must change the From address. But we have scripts that use mailx which cannot be re-written to use any extra flags, so I'd like to use internal variables instead, which I see on the linux.die.net manpage on mailx is an alternative to the -r flag:

-r address
Sets the From address. Overrides any from variable specified in environment or startup files. Tilde escapes are disabled. The -r address options are passed to the mail transfer agent unless SMTP is used. This option exists for compatibility only; it is recommended to set the from variable directly instead.

(Source: http://linux.die.net/man/1/mailx)

How can we use these mailx variables? I tried adding this to /root/.mailrc, no go:

set from=FromAddress@Example.com

I also added that to /etc/mail.rc with no gold. So I am turning to you, SuperUsers...

SlowBro

Posted 2013-09-23T23:08:16.200

Reputation: 51

Answers

2

Neither using -r nor setting the from variable worked in my environment.

I always got something like:

send-mail: 550 5.7.1 ... Invalid from address ....

What worked for me was adding an sSMTP alias to /etc/ssmtp/revaliases, e.g.

accountname:root@machinename.example.com:smtp.example.com

lava37

Posted 2013-09-23T23:08:16.200

Reputation: 47

2

I'm sure versions matter, but I just struggled with this very problem on RH Server 6.7, having misread the mailx manpage, but eventually I got ~/.mailrc to work.

set from=user@example.com
set replyto=user@example.com

doing both from and replyto is probably unnecessary, but if it's worth doing, it's worth overdoing!

Richard Betel

Posted 2013-09-23T23:08:16.200

Reputation: 41

2

I just tested this in Ubuntu 14.04 and using the -S parameter worked for me:

-S variable[=value]
          Sets the internal option variable and, in case of a string option, assigns value to it.

So, the following command sets the from address to "test@exmaple.org":

echo "This is my test" | mail -S from="test@example.org" -s "This is my subject" "receiver@exmaple.org"

Benjamin

Posted 2013-09-23T23:08:16.200

Reputation: 21

1

To add to Richard Betel's answer, you can also specify a full email address in .mailrc, like:

set from="John Smith <john@example.com>"

John

Posted 2013-09-23T23:08:16.200

Reputation: 106

1

Apparently it's not possible to set a mailx variable to do this. This is done with a Sendmail (or equivalent MTA) configuration. But unfortunately no Sendmail configuration was workable for us, and we have to use the -r flag.

SlowBro

Posted 2013-09-23T23:08:16.200

Reputation: 51

Debian 9 stretch, mailx: option -r works, option -S not available – woohoo – 2018-04-21T14:40:42.930