2

I am losing line endings when sending an email from Linux to Windows using 'mail'.

I have tried all ways of doing this, setting the multiline 'body' text as a variable and then piping this into mail, using here-document style input of a text file into mail. Either way, when the email arrives in Windows Outlook I lose all my line endings.

releasenotes=$(tail -n5 ./ReleaseNote)
echo -e "$releasenotes" | mail -s "$ALERT_EMAIL_SUBJECT" "$ALERT_EMAIL_ADDR"

I can confirm the ./ReleaseNote file does indeed have the line endings in place.

I have tried doing a unix2dos conversion but the email then arrives in Outlook with a .bin attachment.

Can anyone help ? I have spent hours on this tonight.

AnFi
  • 6,103
  • 1
  • 14
  • 27
ilium007
  • 393
  • 1
  • 5
  • 7

2 Answers2

2

Use sed to remove \r characters:

echo -e "$releasenotes" | sed 's/\r//' | mail -s "$ALERT_EMAIL_SUBJECT" "$ALERT_EMAIL_ADDR"
Jim
  • 21
  • 2
0

If possible to suggest a fix to the recipients, there's a setting in Outlook:

For Outlook 2010 and later versions:

  1. Open Outlook.
  2. On the File tab, select Options.
  3. In the Options dialog, select Mail.
  4. In the Message format section, clear the Remove extra line breaks in plain text messages check box.
  5. Select OK.

For Outlook 2007 or earlier versions:

  1. Open Outlook.
  2. On the Tools menu, select Options.
  3. On the Preferences tab, select the E-mail Options button.
  4. Clear the Remove extra line breaks in plain text messages check box.
  5. Select OK two times.

https://docs.microsoft.com/en-us/outlook/troubleshoot/message-body/line-breaks-are-removed-in-posts-made-in-plain-text

Richlv
  • 2,354
  • 1
  • 13
  • 18