.dat instead of text using mailx on RedHat Linux

I am trying to send the contents of a text file as an attachment body. This works fine on HP-UX, but we recently switched to RedHat Linux and it no longer works properly.

Here is my team

cat test.txt | mailx -sTest me@email.ca

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. It seems that when I try to send these characters, Linux converts the email into an application (in the form of attxxxxx.dat). The attachment has all my data perfectly formed, but my recipients just want a regular email - not a dat application. We tried to set environment variables and enter extended character set commands in the mailx command, but to no avail.

Any suggestions or ideas are welcome.

+4
source share
3 answers

Make sure your file encoding matches the language setting (language system) installed on your system. Either convert the file (for example, using iconv ) to the appropriate locale, or set the system locale to the current encoding of the file. Also, be sure to remove any carriages from the file.

cat test_1.txt | tr -d '\r' > test_2.txt;

Then cat test_2.txt | mailx -s 'Test' me@email.ca ; cat test_2.txt | mailx -s 'Test' me@email.ca ; should work correctly.

+2
source

you can also use below a small perl script before sending the file by email

 perl -pi -e 's/\r\n/\n/g' file_name 
+1
source

According to Toru's answer, I was tuned to this command:

 cat $FILE | tr -c -d '[:graph:][:blank:]\n\r\t' | mail -s "$FILE" somebody@example.com 
0
source

Source: https://habr.com/ru/post/1500601/


All Articles