.dat attachment instead of text using mailx in RedHat Linux

非 Y 不嫁゛ 提交于 2020-01-02 04:42:08

问题


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 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 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.


回答1:


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' me@email.ca; should work correctly.




回答2:


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



回答3:


As per Toru's answer, I've been settled down to this command:

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


来源:https://stackoverflow.com/questions/18621899/dat-attachment-instead-of-text-using-mailx-in-redhat-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!