I've been using
mail -s "here is a log file" "person@example.com" < log/logfile.log
Which used to come through with headers:
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
But now the files are longer I'm getting noname attachments because with this:
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
So if all else fails, check the manual man mail
...
NAME
mailx - send and receive Internet mail
SYNOPSIS
mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops]
[-A account] [-S variable[=value]] to-addr . . .
None of these options seem useful so how can I force Content-Type: text/plain
?
I got the similar problem recently and finally end up with a solution that is shorter:
More details of the discussion of cat with mailx.
I had some trouble to get my automatic email scripts to run after changing to Ubuntu Precise 12.04. I don't know, when Ubuntu (or Debian) exchanged bsd-mailx against heirloom-mailx, but the two "mail"-commands behave very differently. (E.g. heirloom uses -a for attachments, while it's used for additional headers in bsd.) In my case heirloom-mailx wasn't able to reliably determine the Mime type and kept sending text as attachments. Blame me for not weeding out control characters or whatever, but I don't see much point in changing scripts that did their job perfectly before the upgrade. So if you prefer setting the Mimetype yourself, bsd-mailx is a better solution.
Solved it for me.
In my case, the script was called from cron where LC_* was not defined and accents were interpreted as "control chars". I just inserted the following lines at the beginning of my crontab file :
On RedHat based systems (SL, CentOS, Fedora, etc.), you will want to install bsd-mailx and then set /etc/alternatives/mail appropriately:
Of course, you risk breaking applications that rely on heirloom-mailx behavior but do not explicitly call 'mailx' instead of 'mail'.
To display information about /bin/mail currently points to:
To check for various installed mailx packages:
The man page is a good place to start! Keep reading until you get to the
MIME TYPES
section, and pay close attention the following:So, if your message contains "formatting characters" (which in general means control characters) other than newlines and tabs, it will automatically be classified as
application/octet-stream
. I bet that if you look closely at the data you'll find some control characters floating around.You can work around this by...
-a
) instead of the main message body, and set up your~/.mime.types
file to identify*.log
files as text/plain.tr
.Use another MUA such as
mutt
to send the mail. In fact, you could just craft a message yourself and send it directly tosendmail
: