Adding 'from' email address alias in Linux.

Hi Experts,

We want to add the 'from' email address to mailx command in all our linux script. After searching this site I am able to find the command '-- -f' to add the from the email address. Bu the problem is our from email address is :- "Proper Support Name <support@company.com>"
Now when I am running mailx command I am getting email from 'support@company.com', but I need to have "Proper Support Name" (alias).

Could you please let me know how can we add the email alias ("Proper Support Name" in this case) in the from email address?
Command which I tried so far:-

mailx  -s  "`hostname` : ${Subj}" ${list} -- -f "From: \"Proper Support Name \" <support@company.com> \n\n" < 1.txt

mailx  -s  "`hostname` : ${Subj}" ${list} -- -f "Proper Support Name<support@company.com>" < 1.txt

mailx  -s  "`hostname` : ${Subj}" ${list} -- -f "Proper Support Name"<support@company.com> < 1.txt

The sendmail compatibility options `-F' and `-f' after `--' do not appear to be in mailx anymore.
man mailx do not show any longer [-- sendmail-options ...]

However, looking at it, it appears to have an -S from= variable that you can use for the same purpose.

See if this will help

mailx -s "`hostname` : ${Subj}" -S "from=Proper Support Name <support@company.com>" ${list} < 1.txt

Make sure that you do not add the recipient anywhere else but as the last argument or it will fail. I am assuming that it is ${list}

mailx -s "Subject" -r "from_address@test.com" "to_address@test.com"

mailx -r does set as well the Return-Path which may or may not be what is wanted, and if the format "Name Title <me@here.com>" is given as requested, the Return-Path gets <me@here.com> which is not valid.

As per the documentation:

Thanks all for the help!

Aia,

I have tried the "-S" option, but the command is failing with error message as

mailx: invalid option -- S
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...
            [-- sendmail-options ...]

and yes, you are right '-r' option is not available... :frowning:

Appreciate all your help!!

It appears that your mailx program is not a real binary but rather a symbolic link to the mail program. Futher more, your mail binary supports the compatible sendmail options. Are you in redhat 5.x?

Anyway, in that case your initial try was close.

mailx -s  "`hostname` : ${Subj}" ${list} -- -F"Proper Support Name" < 1.txt

Yes, we are on Redhat Linux 5.8

Found a workaround, instead of using mailx command we used 'sendmail' command.
From sendmail it is easy to mention the 'from' email address. :slight_smile:

(
 echo "From: ${from1}"
 echo "Subject: ${Subj}"
cat 1.txt
) | /usr/sbin/sendmail ${list}