need a solution for line breaks

fishjie

Senior member
Apr 22, 2006
234
0
76
www.youtube.com
Hi I am writing some code on asp.net and C# that creates email. It uses "\r\n" for its linebreaks for the plain text version of the email. However, this causes "^M" to appear when the email is viewed in Linux. From what I've been reading,

Windows uses "\r\n" for linebreaks
Linux uses "\n"
Mac uses "\r"

First, is this information correct? And second, if it is indeed correct, then how can I create a plaintext email with linebreaks that work on all the different operating systems? what solutions do people usually use?
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
System.Environment.NewLine works on Windows and Linux, so possible will work on Mac's
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Originally posted by: joshsquall
Originally posted by: Snapster
System.Environment.NewLine works on Windows and Linux, so possible will work on Mac's

Ding ding ding.

Am I missing something? System.Environment.NewLine will only use the proper newline character(s) for the system on which the executable is running. The OP's issue is with the email client (on an unknown OS) that may be viewing the email. If the app is running on a Windows host, the email will be generated with \r\n as the newline and will still look incorrect on his test Linux email client.
 

fishjie

Senior member
Apr 22, 2006
234
0
76
www.youtube.com
You are actually right. The problem is, there is no way of knowing what system will read that email, and how it will handle its newlines. I've done some more reading, and I think the majority of email RFCs require that newlines be in \r\n format. If this is indeed the standard, then it is up to the email clients of the various operating systems to convert to their newline format.

I was mainly wondering if anyone else has encountered this problem before, and if indeed the only solution is to stick to the \r\n and hope that clients comply?
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
I guess correct in that if you look at it from outside the box, you can't write an email will will detect which client/os it is on. \r\n Would probably be the safest bet and hope that the client is of standard.
 

Gunslinger08

Lifer
Nov 18, 2001
13,234
2
81
Originally posted by: Snapster
I guess correct in that if you look at it from outside the box, you can't write an email will will detect which client/os it is on. \r\n Would probably be the safest bet and hope that the client is of standard.

Or just use HTML and tell users who use a text email client to upgrade.