mail: Invalid header when sending mail attachment with Ubuntu

user246977 picture user246977 · Aug 4, 2016 · Viewed 8.3k times · Source

This exact question was posted by user 'anvd' on 29th July but then removed - I found it on Google Cached version...!

I'm guessing the fix was something obvious, but would be great if it wasn't removed.

I am trying this command to send an email with an attachment.

echo 'These are contents of my daily backup' | mail -s 'Daily backup' -a /tmp/filename.gz [email protected]

The error: mail: Invalid header: /tmp/filename.gz

The email gets sent, but the attachment is not attached.

This used to work, and still dos on other systems, but not sure what has changed on one of my machines...

Answer

Kyle_S-C picture Kyle_S-C · Dec 15, 2016

I just had this problem. It turns out that -a is the flag for appending headers, whereas -A is the flag for attaching files.