email format with line breaks in vb.net

Joseph Hedbon 161 Reputation points
2022-06-21T22:56:03.363+00:00

i've been looking around and tried a few different coding ways to get the email body to have line breaks, and i can not seem to get it to work. the email populates correctly with everything it needs. just can't get the message body to have line breaks. i have tried. <br>, appendline, vbnewline, and vbcrlf. and no luck. any help would be appreciated. i do not know if i need to add a resource at the beginning of the class if thats the hang up.

Option Strict On
Option Explicit On

Public Class NewHireEmail
Dim firstname As String
Dim lastname As String
Dim firstlastname As String
Dim NPN As String
Dim MGA As String
Dim GA As String
Dim SA As String
Dim trainingclass As String

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked  
    Process.Start("https://nipr.com/help/look-up-your-npn")  
End Sub  

Public Sub NewAgent()  
    firstname = TextBox1.Text  
    lastname = TextBox2.Text  
    firstlastname = firstname + " " + lastname  
End Sub  
Public Sub dateofclass()  

    trainingclass = DateTimePicker1.Value.ToString("d")  

End Sub  
Public Sub NPNNumber()  
    NPN = TextBox3.Text  
End Sub  

Public Sub ManagerHierarchy()  
    MGA = TextBox4.Text  
    GA = TextBox5.Text  
    SA = TextBox6.Text  
End Sub  

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  

    Dim body As String  
    Dim subject As String  
    Dim address As String  




    If RadioButton1.Checked = True Then  
        Call NewAgent()  
        Call NPNNumber()  
        Call ManagerHierarchy()  


        address = "******@test.com"  
        subject = "New Hire " & firstlastname  
        body = "hello <br> hello <br> hello"  



        Process.Start(String.Format("mailto:{0}?subject={1}&body={2}", address, subject, body))  

    End If  

End Sub  

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged  
    If RadioButton1.Checked = True Then  
        RadioButton2.Checked = False  
        Label9.Visible = False  
        DateTimePicker1.Visible = False  
    End If  
End Sub  

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged  
    If RadioButton2.Checked = True Then  
        RadioButton1.Checked = False  
        Label9.Visible = True  
        DateTimePicker1.Visible = True  

    End If  
End Sub  

End Class

Developer technologies Visual Basic for Applications
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2022-06-22T07:58:12.627+00:00

    Check this:

    body = "hello%0D%0Ahello%0D%0Ahello"

    0 comments No comments

  2. LesHay 7,141 Reputation points
    2022-06-22T12:38:01.517+00:00

    Hi
    Further to the reply by Viorel.

    This example uses the text from a TextBox1 on the Form for the email body.

    		Dim body As String  
    		Dim subject As String  
    		Dim address As String  
      
    		' plain text email use %0D%0A  
    		' HTML text use tag instead   <br/>  
    		Dim mynewline As String = "%0D%0A"  
      
    		address = "******@test.com"  
    		subject = "New Hire " & "Freddy MacBloggs"  
      
    		body = TextBox1.Text.Replace(vbCrLf, mynewline)  
      
    		Process.Start(String.Format("mailto:{0}?subject={1}&body={2}", address, subject, body))  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.