1

I am trying to send the contents of a logfile via email like this:

sendmail -f [email protected] [email protected] < /private/var/log/mylog

Unfortunately, this does not work – the email arrives in the inbox but is empty.

The same is true for this variation:

echo "$(</private/var/log/mylog)" | sendmail -f [email protected] [email protected]

But when echoing some string like this:

echo "testing" | sendmail -f [email protected] [email protected]

the email arrives with the content. Also, using cat to view the file's content works too. This leads me to the conclusion that is has to be something with the way I wrote the command, but I don't see any syntax problem or similar.

What am I missing – why do the emails arrive empty when trying to send the file contents?

Seth
  • 528
  • 3
  • 16
  • 32
Sven
  • 12,997
  • 27
  • 90
  • 148
  • Could be because of a mail body limitation if your log file is greater than a few megabytes. Try this http://stackoverflow.com/questions/1333097/how-to-send-a-html-email-with-the-bash-command-sendmail – LMC Feb 23 '17 at 23:17

1 Answers1

2

sendmail expects "raw" message (headers and body separated by an empty line) over its standard input.

Try the command below

(echo Subject: Logfile; echo; cat /private/var/log/mylog) | sendmail -i -f [email protected] [email protected] 

-f [email protected] - set envelope sender address to [email protected]
-i - do not treat lines starting with . special

AnFi
  • 10,493
  • 3
  • 23
  • 47