Help! MailMessage Body is stripping carriage return/line feeds

Discussion in 'Microsoft Dot NET' started by Tim Mavers, Feb 27, 2004.

  1. Tim Mavers

    Tim Mavers Guest

    I am using the MailMessage class and am dynamically building the message
    body field. I know I am using String and not String builder but I don't
    want to worry about that now. The problem is after I build my message
    (which contains CR\LFs -- blank lines), the message received by the user
    has all the cr\lf's removed from the message body so that everything is
    on one line.

    I have tried using "\n", "\n\r", Environment.NewLine, and
    Environment.NeLines.ToString() (only because I saw this last method on
    Google).

    Anyway, I have viewed the message in Outlook and Outlook Web Access
    (through IE 6) and they look the same, so I am pretty confident the
    client is not removing anything. Here's a quick sample of the code:

    String msgBody = "The following information was received by the fax
    server.:" + Environment.NewLine.ToString() + Environment.NewLine.ToString();

    ---sample code---
    msgBody += "Date: " + data.Date + " " + data.Time +
    Environment.NewLine.ToString();

    msgBody += "Machine: " + data.Computer + Environment.NewLine.ToString();

    msgBody += "User: " + Environment.NewLine.ToString()

    msgBody += "File: " + data.ObjectName + Environment.NewLine.ToString();
    ---sample code---

    Again, when I receive this message the entire message above is all on
    one line.

    Is there a C# equivalent of the old VbCrLf (I assumed it was
    Environment.NewLine?

    Any other ideas?

    Thanks!
     
    Tim Mavers, Feb 27, 2004
    #1
    1. Advertisements

  2. Tim Mavers

    Bill Guest

    You must use "\r\n"

    Also if you are using in HTML use "<BR>" instead. (This is a common
    mistake.)

    Bill


    "Tim Mavers" <> wrote in message
    news:...
    > I am using the MailMessage class and am dynamically building the message
    > body field. I know I am using String and not String builder but I don't
    > want to worry about that now. The problem is after I build my message
    > (which contains CR\LFs -- blank lines), the message received by the user
    > has all the cr\lf's removed from the message body so that everything is
    > on one line.
    >
    > I have tried using "\n", "\n\r", Environment.NewLine, and
    > Environment.NeLines.ToString() (only because I saw this last method on
    > Google).
    >
    > Anyway, I have viewed the message in Outlook and Outlook Web Access
    > (through IE 6) and they look the same, so I am pretty confident the
    > client is not removing anything. Here's a quick sample of the code:
    >
    > String msgBody = "The following information was received by the fax
    > server.:" + Environment.NewLine.ToString() +

    Environment.NewLine.ToString();
    >
    > ---sample code---
    > msgBody += "Date: " + data.Date + " " + data.Time +
    > Environment.NewLine.ToString();
    >
    > msgBody += "Machine: " + data.Computer + Environment.NewLine.ToString();
    >
    > msgBody += "User: " + Environment.NewLine.ToString()
    >
    > msgBody += "File: " + data.ObjectName + Environment.NewLine.ToString();
    > ---sample code---
    >
    > Again, when I receive this message the entire message above is all on
    > one line.
    >
    > Is there a C# equivalent of the old VbCrLf (I assumed it was
    > Environment.NewLine?
    >
    > Any other ideas?
    >
    > Thanks!
     
    Bill, Feb 27, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bizzo

    Unable to add a new line do a MailMessage

    Bizzo, Jul 14, 2003, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    621
    Marina
    Jul 14, 2003
  2. Burak
    Replies:
    2
    Views:
    183
  3. Alin Popovici

    Carriage Return in WebMethods

    Alin Popovici, Jan 8, 2004, in forum: Microsoft Dot NET
    Replies:
    0
    Views:
    598
    Alin Popovici
    Jan 8, 2004
  4. Guest

    MailMessage - inserting new line character

    Guest, Nov 9, 2004, in forum: Microsoft Dot NET
    Replies:
    1
    Views:
    315
    Guest
    Nov 9, 2004
  5. Guest

    MailMessage with a large body

    Guest, Jan 13, 2005, in forum: Microsoft Dot NET
    Replies:
    4
    Views:
    1,446
    John Timney \(ASP.NET MVP\)
    Jan 15, 2005
Loading...

Share This Page