I am trying to send the contents of a text file as the body of an attachment. This works fine in HP-UX, but we've recently moved to RedHat Linux, and it is no longer working as expected.
Here's my command
cat test.txt | mailx -sTest [email protected]
If "test.txt" contains low ASCII characters, then it works fine. However, my text file may have French characters and will always contain a registered trademark symbol. It seems that when I try to send those characters, Linux is converting the email into an attachment (in the form attxxxxx.dat). The attachment has all my data, perfectly formed, but my recipients just want a plain email - not a "dat" attachment. We've tried setting the environment variables and putting extended character set commands in the mailx command, to no avail.
Any suggestions or ideas would be greatly appreciated.
Make sure that your file encoding is the same as the locale (man locale) set on your system. Either convert your file (e.g. using iconv
) to the according locale or set the locale of the system to the current file encoding. Moreover make sure to remove any carriage returns from the file
cat test_1.txt | tr -d '\r' > test_2.txt;
Then cat test_2.txt | mailx -s 'Test' [email protected];
should work correctly.
you can also use below small perl script before you send the file via mail command
perl -pi -e 's/\r\n/\n/g' file_name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With