homer
homer

Reputation: 433

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

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>

Upvotes: 5

Views: 28319

Answers (1)

JeffM
JeffM

Reputation: 385

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.

Upvotes: 2

Related Questions