How do I create line breaks in a string to be passed to email app?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to start my email app (in this case Eudora) with a
programatically generated email. However, Eudora does not seem to recognize
any of the ways I have tried to create line breaks.

I have tried "\n", "\r\n", and using the StringBuilder AppendLine() method
like this:

StringBuilder body = new StringBuilder(1024);

// AppendLine doesn't work
body.AppendLine("Thank you for registering!");

// Neither does this
body.Append(System.Environment.NewLine);
body.Append("Support Forums");
body.AppendLine();
body.Append("Please be sure that you have the latest version, ");

Process process = new Process();
process.StartInfo.FileName = "mailto:";
process.StartInfo.FileName += tbEmail.Text;
process.StartInfo.FileName += "?subject=GaugeGlow License Key";
process.StartInfo.FileName += "&[email protected]";
process.StartInfo.FileName += "&body=";
process.StartInfo.FileName += body;

process.Start();

yet, when the email opens in the application, there are no line breaks at all.

Stick
 
Stick,

You might want to try URL encoding the body part of the url. It might
work then.
 
Stick,

I am not sure in this case, however that mostly the <br> does help in some
case (if your text is used in the mail as html) would I try that in your
situation first.

Cor
 
I found this from the C# specification.

9.3.1 Line terminators

31 Line terminators divide the characters of a C# source file into lines.

32 new-line::

33 Carriage return character (U+000D)

34 Line feed character (U+000A)

35 Carriage return character (U+000D) followed by line feed character
(U+000A)

36 Next line character (U+0085)

37 Line separator character (U+2028)

38 Paragraph separator character (U+2029)

39 For compatibility with source code editing tools that add end-of-file
markers, and to enable a source file to be

40 viewed as a sequence of properly terminated lines, the following
transformations are applied, in order, to every

41 source file in a C# program:

42 . If the last character of the source file is a Control-Z character
(U+001A), this character is deleted.

43 . A carriage-return character (U+000D) is added to the end of the source
file if that source file is non-empty

44 and if the last character of the source file is not a carriage return
(U+000D), a line feed (U+000A), a line

45 separator (U+2028), or a paragraph separator (U+2029).

You can download it from:
http://msdn.microsoft.com/netframework/programming/clr/default.aspx

if you wish. Good luck

chanmm
 
Cor,

Cor Ligthert said:
Stick,

I am not sure in this case, however that mostly the <br> does help in some
case (if your text is used in the mail as html) would I try that in your
situation first.

Yes, my first thought too, but didn't work.

Stick
 
Nicholas,

Nicholas Paldino said:
You might want to try URL encoding the body part of the url. It might
work then.

Hmmmm. I did an MSDN search, but don't see that it is possible to set this
format with the class I'm using, and I'm not too sure how to do it another
way. But thanks for the idea.
 
Stick,

Use the static UrlEncode method on the HttpUtility class in the
System.Web namespace. You will have to add a reference to System.Web.dll to
do this as well.
 
Back
Top