How to format the body of outgoing emails in C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashir
    New Member
    • May 2010
    • 2

    How to format the body of outgoing emails in C#?

    mailMessage.Bod y = "text1 : " + txtBody.Text;
    mailMessage.Bod y += "text2 : " + TextBox1.Text;

    out put:
    >text1 xyz text2 xyz

    I want to seperete these two lines in mail which i got
    as
    >text1 : xyz
    >text2 : xyz

    please reply me how to do it......
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    May I suggest picking up a basic C# introductory book? It's not that people here don't want to be helpful, but there is a certain amount of basic learning work that one should really take upon themselves before asking for help. There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" books at your look book seller or even public library... Asking a forum, any forum, to hand-hold you through it is just redundant. In many ways it disrespects the people who have invested dozens of hours in the on-line tutorials and those that spent thousands of hours in authoring books.

    Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
    is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

    C# Cookbooks
    Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

    Microsoft Visual Studio Tip, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
    Has many, many great, real-world tips that I use all the time.

    The tutorials below walk through making an application including inheritance, custom events and custom controls.
    Building an application Part 1
    Building an application part 2

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      You need to learn how to do basic string editing.
      You can insert special control characters such as
      \t for tab
      \n for newline
      and so on. This would all be covered in any of the "My first program" tutorials online or in a "Learning C# for the beginner" book.

      Comment

      • ashir
        New Member
        • May 2010
        • 2

        #4
        Originally posted by tlhintoq
        May I suggest picking up a basic C# introductory book? It's not that people here don't want to be helpful, but there is a certain amount of basic learning work that one should really take upon themselves before asking for help. There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" books at your look book seller or even public library... Asking a forum, any forum, to hand-hold you through it is just redundant. In many ways it disrespects the people who have invested dozens of hours in the on-line tutorials and those that spent thousands of hours in authoring books.

        Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
        is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

        C# Cookbooks
        Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

        Microsoft Visual Studio Tip, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
        Has many, many great, real-world tips that I use all the time.

        The tutorials below walk through making an application including inheritance, custom events and custom controls.
        Building an application Part 1
        Building an application part 2
        Thanks a lot giving me reply but i am talking about specifically body part in mail i had used

        1.
        mailMessage.Bod y = "text1 : " + txtBody.Text + "\n";
        mailMessage.Bod y += "text2 : " + TextBox1.Text;

        2.
        mailMessage.Bod y = "text1 : " + txtBody.Text + "\r\n";
        mailMessage.Bod y += "text2 : " + TextBox1.Text;

        3.
        mailMessage.Bod y = "text1 : " + txtBody.Text + "Environment.Ne wLine";
        mailMessage.Bod y += "text2 : " + TextBox1.Text;

        all these three but nothing is working at mail part means when the person got mail in his mail's body part output is coming as i show for all above three as following :
        output :
        >text1 xyz text2 xyz

        so i ask how can i divide lines in different rows as

        >text1 xyz
        >text2 xyz
        please now reply me if you can ...
        Thanks a lot for reply my question.
        Thanks With Regards,
        Ashir

        Comment

        • PRR
          Recognized Expert Contributor
          • Dec 2007
          • 750

          #5
          Use System.Environm ent.NewLine in your message text

          Set the MailMessage.IsB odyHtml
          and use html elements in a string and add it to the body of mail message.
          Last edited by Niheel; Mar 1 '11, 06:35 AM.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            You are just thrashing about wildly. Trying to guess a way to do this, rather than read and learn and comprehend.

            Code:
            mailMessage.Body = "text1 : " + txtBody.Text + "Environment.NewLine";
            If your wrap quotions around "Environment.Ne wLine" it is not a variable. It is just text that says Environment.New Line.

            Code:
            mailMessage.Body += "\n\nText2: THis is my second line of text";

            Comment

            Working...