views:

270

answers:

4

I've got an application that sends nicely formatted processing logs to the user.

When I run the application locally (debug mode), using [SMTPServer] to send, the logs arrive neatly formatted and look as I'd expect.

When I install the application on a testing server and configure it to use the same [SMTPServer] to send, the logs arrive in my Inbox with the line breaks removed.

Converting to HTML format is not really an option right now.

I realize that Outlook strips them, but I'm confused as to why it does it only when coming from the server.

Thoughts?

+1  A: 

What code is it that introduces the line breaks? If the code for sending the mails is identical, and it is sent through the same server and consumed by the same client, I would investigate the source; the logs themselves. Can they look different when produced on the server, compared to how they come out when the system is run locally?

Fredrik Mörk
I'm using a StringBuilder with a call to AppendFormat() followed by a call to AppendLine().I'm wondering if maybe the default line terminator is different on the server (W2K3) than on my development machine (Vista).Something to look at...thanks.
+1  A: 

Try writing the log information out to a file on both boxes to see if there is a difference in the output. If they are the same then the problem is likely in the configuration of the mail server, possibly with the default email encoding or something like that. If they are different then you can setup remote debugging to the server to inspect the string/email as you build it to see if you can find the variant.

I have never seen a different line terminator between Vista and 2003 (in default configurations), but I agree it is something to look at...

Brian ONeil
+2  A: 

I'm not sure this would fix it, but try to add a line break by either using:

System.Environment.NewLine

or simply "\n". The former is better practice, though.

Stefan
+1. Check this for more info http://ablog.apress.com/?p=967
David HAust
Shouldn't the AppendLine() method of StringBuilder handle that for me? I'll give it a go.
A: 

Hi,

In the email world, lines can only be terminated with "\r\n" (vbCrLf). Using Environment.NewLine or "\n" or "\r" is incorrect, and can lead to problems.

New lines must be terminated with the combination of "\r\n" (without quotes).

I don't know if that is the problem here, however, if you are building an email using StringBuilder, the correct way to do this is:

sb.Append( singleLineContent);
sb.Append( "\r\n" );

Cheers!

Dave

dave wanta