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?
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.
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.
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.
You can use the "-r" option to set the sender address:
mailx -r [email protected] -s ...
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]>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With