Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the From email address for mailx command?

I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the email via mailx.

Question: How do I set the "From" email address on the mailx command?

Current Code:

echo ${msg_txt} | mailx -s "Script Failure" ${to_email} 

Note: The command works fine, however, the "From" is the name of the user I am running the script as and I would like for this to another email address.

How would I accomplish this?

like image 200
AieshaDot Avatar asked Aug 18 '09 22:08

AieshaDot


People also ask

How do I change the sender name in mailx?

The Usage info shows "[-- sendmail-options ...]" and since "-r" is a sendmail option, you need to use the double dashes first. Show activity on this post. The double-dash before "-f" makes the mailx not to parse the -f, but only pass it to sendmail/postfix, which will then send with the "from" address mentioned.

How do I specify an address from an email in Linux?

Specify the sender name and address To specify the additional information with the mail command, use the -a option with the command. Execute the command as follows: $ echo "Message body" | mail -s "Subject" -aFrom:Sender_name\<Sender mail address\> recipient address.

What mail server does mailx use?

smtp Normally, mailx invokes sendmail(8) directly to transfer messages. If the smtp variable is set, a SMTP connection to the server specified by the value of this variable is used instead.


2 Answers

You can use the "-r" option to set the sender address:

mailx -r [email protected] -s ... 
like image 113
sth Avatar answered Nov 09 '22 05:11

sth


The "-r" option is invalid on my systems. I had to use a different syntax for the "From" field.

-a "From: Foo Bar <[email protected]>" 
like image 42
Finch_Powers Avatar answered Nov 09 '22 05:11

Finch_Powers