Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use mailx to send file as text and add extra text to email body?

Tags:

shell

ksh

mailx

How to send some text in email along with the contents of the file, don't want to send file as an attachment? is it possible via mailx command?

mailx -s "Email log file" [email protected] <$log_file;

$log_file contents gets emailed but below doesn't work

echo "Comment: log contains last month report" | mailx -s "Email log file" [email protected] < $log_file

Needed output in email:

Comment: Log contains last month report

 <All contents of $LOG_FILE as text>
like image 398
homer Avatar asked Nov 01 '22 11:11

homer


1 Answers

Here is how you would do it:

echo "Comment: log contains last month report\n $(cat \$log_file)" | mailx -s "Email log file" [email protected]

The only thing "funny" is you'll have to escape that $ in the filename. You can also add more new lines \n if need be.

like image 106
JeffM Avatar answered Nov 09 '22 09:11

JeffM