1
~ > which mail
/bin/mail
~ > ls -la /bin/mail
lrwxrwxrwx 1 root root 22 Feb 25 14:18 /bin/mail -> /etc/alternatives/mail

According to man mail,

-E If an outgoing message does not contain any text in its first or only message part, do not send it but discard it silently, effectively setting the skipemptybody variable at program startup. This is useful for sending messages from scripts started by cron(8).

However, even with -E, my cron script, which uses echo, still sends empty messages. What happens is (essentially) this:

logmsg=""
echo "$logmsg" | mail -E -s "Log Message" me@mydomain.tld

Have I misunderstood something? Why does mail -E send emails with empty messages?

skyler
  • 465
  • 3
  • 7
  • 17
  • 1
    Your empty `echo ""` is still a message, albeit one consisting of an empty line. what happens when you omit the line end with `echo -n ""` ? – HBruijn Jul 10 '14 at 15:10
  • echo -n prints nothing and goes to the next line in my terminal. – skyler Jul 10 '14 at 15:29

2 Answers2

1

Your email contains a subject so it's not empty. What happens when you try to send it without -s "Log Message"?

  • `echo "" | mail me@mydomain.tld` doesn't send an email, even without the `-E` flag. Mail's man for `-E` says "If an outgoing message does not contain any text in its first or only message part, do not send it but discard it silently." Specifically it says "part" which indicates to me that it's talking about MIME parts. Not a subject, which isn't a MIME part. – skyler Jul 10 '14 at 15:37
1

HBruijn's comment fixed this for me - in other words:

This email was sent:

echo '' | mail -E -s "echo ''" root

but this one wasn't:

echo -n '' | mail -E -s "echo -n ''" root
jogwen
  • 11
  • 1