Results 1 to 6 of 6

Thread: [RESOLVED] New line in email body

  1. #1

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    304

    Resolved [RESOLVED] New line in email body

    I have been trying for a while to send an email in code using the default mail client. I have this code which works, however I can not get the body to be multi line.

    VB.net Code:
    1. Imports System.Net.Mail
    2. Imports System.IO
    3. Imports System.Text
    4.  
    5.  
    6.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    7.  
    8.         Dim L1 As String = TextBox5.Text
    9.         Dim L2 As String = TextBox6.Text
    10.         Dim L3 As String = TextBox7.Text
    11. Dim TITLE As String = TextBox1.Text
    12. Dim BODY As String
    13.  
    14.         RichTextBox1.Text = (RichTextBox1.Text & "" & L1 & Environment.NewLine)
    15.         RichTextBox1.Text = (RichTextBox1.Text & "" & L2 & Environment.NewLine)
    16.         RichTextBox1.Text = (RichTextBox1.Text & "" & L3 & Environment.NewLine)
    17.  
    18. BODY = RichTextBox1.Text
    19.  
    20.         Dim proc As System.Diagnostics.Process
    21.         proc = New System.Diagnostics.Process()
    22.         proc.StartInfo.FileName = "EMAIL@email.com?subject=" &  TITLE & "body=" & BODY & " "
    23.         proc.Start()
    24.  
    25.     End Sub

    This does correctly input the data with new lines into the RichTextBox, however when it opens the mail client the body does not have new lines.
    Is there a way to fix this?

    I have also tried to copy the text from the RTB into the clipboard and paste it into the body, however this does not work either. Any help would be greatly appreciated
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,534

    Re: New line in email body

    Try using %0D%0A for a new line embedded in your string rather than environment.newline.

  3. #3
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,390

    Re: New line in email body

    any reason why you are not using the smtp namepace?

  4. #4

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    304

    Re: New line in email body

    Quote Originally Posted by kevininstructor View Post
    Try using %0D%0A for a new line embedded in your string rather than environment.newline.
    Worked Perfectly! Thank you so much
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

  5. #5

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    304

    Re: New line in email body

    Quote Originally Posted by ident View Post
    any reason why you are not using the smtp namepace?

    Mmmm... dont know? Lol, this worked so I went with it
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,534

    Re: [RESOLVED] New line in email body

    Good that this worked for you. In the future consider ident's suggestion which is best for desktop apps as the method you are currently using is more for web apps than desktop apps but in the end use what works for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width