I am using this code to send an email on my code
in this below code subject and mail body we are getting form dataset and storing in a string .
i didn't have any concern regarding subject but when it comes to body i am facing issue like
for example in my mail body i am having three points i.e, three line
1.some text
2.some text
3.some text
after the mail is triggered my mail body is looking like
1.some text 2.sometex 3.sometext .
here is my piece of code
Try
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential()
SmtpServer.Port = 25
SmtpServer.Host = "email.host.com"
mail = New MailMessage
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
mail.Subject = Subject
mailbody= "<html>" & " <body>" & "<p>" _
& String.Join("</p><p>", mailbody.Split({Environment.NewLine},
StringSplitOptions.None)) _
& " </p>" & "</body> " & " </html>"
mail.Body = mailbody
mail.IsBodyHtml=true
SmtpServer.Send(mail)
catch ex As Exception
MsgBox(ex.ToString)
End Try
is there any way where i can get the exact format .
Please check the below screen shot
After generating the mail still i ma getting the mail is lookin like this
CodePudding user response:
Give this a go:
mailbody = _
"<html>" & " <body>" & "<p>" _
& String.Join("</p><p>", mailbody.Split({Environment.NewLine}, StringSplitOptions.None)) _
& " </p>" & "</body> " & " </html>"
The issue was that you were splitting the lines int he mailbody
and we weren't closing your HTML tags properly.
CodePudding user response:
You are trying to insert the "Enter" in HTML (that doesn't work) replace that by < br/ > You can also replace the "Environment.NewLine" by < br/ >
Use < br/ > in HTML to bring the text to the next line.