Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set from address text in bash mail

Tags:

email

sendmail

I am able to send mail from bash, but cannot change the from text, it currently comes up as 'root'.

I would like email clients to show the following text in the from field script on myserver.com ([email protected]).

How can I do this please?

emailsubject="$scriptname ($scriptver) log at $startdate"

if [ $errorcount > 0 ]; then
    emailsubject="ERRORS($errorcount) - ${emailsubject}"
fi

mail -s "$emailsubject" [email protected] < $logfile
like image 269
morleyc Avatar asked Dec 01 '22 19:12

morleyc


1 Answers

If Your "mail" supports it, You may add custom headers using the -a switch like this:

mail -s "subject" -a "From: [email protected]" ...
like image 125
Roman Hocke Avatar answered Dec 10 '22 19:12

Roman Hocke