My problem is using mailx in a bash script to send a text file (script
result output) to an email address. In some cases with identical
syntax the text file is included in the body of the message, as I would
like, and at other times it comes in as an attachment that shows up in
Pine as "Application/OCTET-STREAM" which Pine cannot easily handle.
After spending considerable time searching the web, I have concluded
that you cannot tell mailx that the file you are trying to send is text.
It would be nice if you could, but you cannot to the best of my
knowledge and I can accept that. What is really bothering me is why
mailx sometimes thinks a text is a text file and other times it does
not. I have looked at the files in both instances in both a text editor
and hex editor and I can see nothing to indicate what mailx is using to
determine what kind of file it is.
My question is, does anyone know what mailx uses to determine how it is
going to handle a text file?
The commands I have tried are as follows.
cat result.txt | mail -s "Results of Script" user
and
mail -s "Results of Script" user < result.txt
I know there are workarounds using a sendmail script of sorts, but it
would be really nice if I could figure out the decision making process
so a single line mail command could be made to work in all cases even if
you had to modify the text file slightly first.
Thanks.
I am posting this in case someone stumbles across my original posting
when trying to solve the same sort of problem. Using a hex editor I
replaced each line in one of the problem files with a string of "A"s one
line at at time until I was able to mail the file without an
"Application/OCTET-STREAM" attachment. In looking at the the last line I
altered I found the byte that was causing the problem. It was hex "OD"
which is a carriage return. A little more research on the web revealed
that there is a "dos2unix" command that strips out those nasty carriage
returns. Once I ran the offending text file through dos2unix, mailx
worked just fine and the complete text file was displayed in the body of
the email.
From now on in my scripts I will have two lines.
dos2unix results.txt
cat results.txt | mail -s Results user
I suspect I just reinvented the wheel and there are many that know about
this already, but I could not find anything in my searches. Perhaps
this will save someone else this exercise.
If you don't have dos2unix in your Linux distribution, and I didn't, you
can find it at "http://hany.sk/~hany/_data/hd2u/". The current package
is hd2u-1.0.3.tgz.
> From now on in my scripts I will have two lines.
>
> dos2unix results.txt
> cat results.txt | mail -s Results user
>
> I suspect I just reinvented the wheel and there are many that know about
> this already, but I could not find anything in my searches. Perhaps
> this will save someone else this exercise.
>
> If you don't have dos2unix in your Linux distribution, and I didn't, you
> can find it at "http://hany.sk/~hany/_data/hd2u/". The current package
> is hd2u-1.0.3.tgz.
Why not
dos2unix results.txt | mail -s Results user
instead? Saves a line, a file creation/write, and a `cat` command
invocation.
--
Most people aren't thought about after they're gone. "I wonder where
Bob got the plutonium" is better than most get.
-- Robert Uhl, in rec.org.sca