Carriage returns in MailMessage object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ant

    #1

    Carriage returns in MailMessage object

    Hi,
    I'm using the MailMessage object to send an email programmaticall y via a
    console application. It needs to have lines breaks. For example:

    string s = "This is the first line + "\n\r" + "and this is the second line.";

    This works fine when written to the console however the MailMessage object
    ignores the \ escape key and returns a single lined string.

    How can I use carriage returns in a MailMessage?

    Many thanks in advance.

  • John Richardson

    #2
    Re: Carriage returns in MailMessage object

    try Environment.New Line?

    "Ant" <Ant@discussion s.microsoft.com > wrote in message
    news:2F96AEA9-64EA-48A6-A789-8284C8F4C9C3@mi crosoft.com...[color=blue]
    > Hi,
    > I'm using the MailMessage object to send an email programmaticall y via a
    > console application. It needs to have lines breaks. For example:
    >
    > string s = "This is the first line + "\n\r" + "and this is the second
    > line.";
    >
    > This works fine when written to the console however the MailMessage object
    > ignores the \ escape key and returns a single lined string.
    >
    > How can I use carriage returns in a MailMessage?
    >
    > Many thanks in advance.
    >[/color]


    Comment

    • Vince Yuan

      #3
      Re: Carriage returns in MailMessage object

      Please use "\r\n" or Environment.New Line

      --
      Vince



      Comment

      • Ant

        #4
        Re: Carriage returns in MailMessage object

        Hi,

        well, I tried both your solutions. "\r\n" gives the same result as "\n\r"
        and Enviroment.NewL ine, is also treated the same. I'm guessing that because
        the email is HTML, it needs a <BR>. Does anybody know how I can send a <BR>
        in a string?

        Many thanks for your thoughts on this

        Ant

        "John Richardson" wrote:
        [color=blue]
        > try Environment.New Line?
        >
        > "Ant" <Ant@discussion s.microsoft.com > wrote in message
        > news:2F96AEA9-64EA-48A6-A789-8284C8F4C9C3@mi crosoft.com...[color=green]
        > > Hi,
        > > I'm using the MailMessage object to send an email programmaticall y via a
        > > console application. It needs to have lines breaks. For example:
        > >
        > > string s = "This is the first line + "\n\r" + "and this is the second
        > > line.";
        > >
        > > This works fine when written to the console however the MailMessage object
        > > ignores the \ escape key and returns a single lined string.
        > >
        > > How can I use carriage returns in a MailMessage?
        > >
        > > Many thanks in advance.
        > >[/color]
        >
        >
        >[/color]

        Comment

        • Ant

          #5
          Re: Carriage returns in MailMessage object

          Actually, I inadvertently answered my own question. Because it is treating
          the text as HTML, I simply added the break to the string i.e.

          "This is the text<BR>This is the next line."

          and it wote it to the email with the breaks.


          "Ant" wrote:
          [color=blue]
          > Hi,
          >
          > well, I tried both your solutions. "\r\n" gives the same result as "\n\r"
          > and Enviroment.NewL ine, is also treated the same. I'm guessing that because
          > the email is HTML, it needs a <BR>. Does anybody know how I can send a <BR>
          > in a string?
          >
          > Many thanks for your thoughts on this
          >
          > Ant
          >
          > "John Richardson" wrote:
          >[color=green]
          > > try Environment.New Line?
          > >
          > > "Ant" <Ant@discussion s.microsoft.com > wrote in message
          > > news:2F96AEA9-64EA-48A6-A789-8284C8F4C9C3@mi crosoft.com...[color=darkred]
          > > > Hi,
          > > > I'm using the MailMessage object to send an email programmaticall y via a
          > > > console application. It needs to have lines breaks. For example:
          > > >
          > > > string s = "This is the first line + "\n\r" + "and this is the second
          > > > line.";
          > > >
          > > > This works fine when written to the console however the MailMessage object
          > > > ignores the \ escape key and returns a single lined string.
          > > >
          > > > How can I use carriage returns in a MailMessage?
          > > >
          > > > Many thanks in advance.
          > > >[/color]
          > >
          > >
          > >[/color][/color]

          Comment

          Working...