views:

1549

answers:

5

I'm creating a big string that ends up getting sent out via email. The string is created as follows:

        For Each NewClaim As BO.ClaimsByPECLogIDRO In NewClaims
        strNewClaims &= Environment.NewLine & NewClaim.ClaimPrefix.ToString _
                        & "-" & NewClaim.ClaimNumber.ToString & " - " & NewClaim.ReportDate.ToString & " - " & _
                        NewClaim.PolicyNumber.ToString & " - " & NewClaim.NoteText.ToString.Replace(vbCrLf, " ").Replace(vbLf, " ").Trim
    Next

The problem is when this gets send out I end up with an Outlook email that says:

"Extra line breaks in this message were removed." and some lines don't have a Newline in them. I can toggle the outlook message and it fixes the display, but I don't see how this code is create extra breaks in the first place.

+1  A: 

This problem is just Outlook trying to be helpful and reformatting your message for you. There's an option in the Outlook options somewhere (I forget where and I'm not at work right now to check) that makes the default the other way around. After changing the setting, Outlook will still give some silly notification but your messages will appear correctly.

Greg Hewgill
A: 

This is just a guess, but maybe it is because it starts out with a newline? Have you tried changing it to

For Each NewClaim As BO.ClaimsByPECLogIDRO In NewClaims        
  strNewClaims &= NewClaim.ClaimPrefix.ToString _
  & "-" & NewClaim.ClaimNumber.ToString & " - " & NewClaim.ReportDate.ToString & " - " _
  & NewClaim.PolicyNumber.ToString & " - " _
  & NewClaim.NoteText.ToString.Replace(vbCrLf, " ").Replace(vbLf, " ").Trim _          
  & Environment.NewLine 
Next

and see if the message still comes up?

tooleb
A: 

I had this today, and triple-checked and rewrote my mail-sending code to make sure I had line breaks where I wanted them, just to find out that this was Outlook's default behavior.

I guess a workaround would be to send HTML mail instead of / in addition to plain text.

devio
+3  A: 

I've tackled this one before:

Include an   (non-breaking space) before each of your NewLine characters.

strBody = strBody.Replace(Environment.NewLine, " " & Environment.NewLine)

Gordon Bell
A: 

This same question also occurs here and here.