0

I have created a file with some different lines of text, like for example:

2345, someinfo1, someinfo2, someinfo3
3567, someinfo1, someinfo2, someinfo3
7812, someinfo1, someinfo2, someinfo3

where someinfo1, someinfo2 and someinfo3 are usually (if not always) different data.

And I need to include the above file output at a mail as body text. So I am doing:

$ cat myfile.txt | mail mymail@mail.com

However, I get to see output of file inside mail body as a single line (like below) and not as it should show with multiple lines, as above:

2345, someinfo1, someinfo2, someinfo3 3567, someinfo1, someinfo2, someinfo3  7812, someinfo1, someinfo2, someinfo3

I need your help to solve this problem. I believe that problem is that mail is using HTML format to display the file and thus file needs to somehow interpret the end of line ($) at all lines of the file so that for every line it will display the next line below current line and not at the same line. I have managed to insert new line at end of every line, but this would display at mail the file with blank line after every line, i.e.:

2345, someinfo1, someinfo2, someinfo3

3567, someinfo1, someinfo2, someinfo3

7812, someinfo1, someinfo2, someinfo3

It shows better than displaying everything in 1 line, however, this is not what I want to do, I don't want to display blank line after every line. Any suggestions to achieve what I need for mail output of file is more than welcome!

Kostas75
  • 331
  • 1
  • 4
  • 13
  • 1
    The code you show does not do what you say it does unless you have some unrelated part somewhere which forces the message to be displayed e.g. as HTML. Can we see the (probably trimmed and anonymized) source of the message you receive? – tripleee Jan 29 '19 at 11:29
  • Try to use `cat myfile.txt | mailx mymail@mail.com -s "this is subject"` – Romeo Ninov Dec 23 '19 at 15:40

1 Answers1

0

Modern mail clients don't understand the plain text format sent by mail or mailx very well, and writing a MIME compliant mail client is not trivial.

What you could try is to change the line endings from \n to \r\n.

cat file | awk '{printf("%s\r\n", $0);}' | mail mymail@mail.com

(Note: on my HP-UX 11.23 sed did not understand \r so I'm using awk here.)

fork2execve
  • 1,561
  • 11
  • 16