cbdrako99
asked on
How to insert a line feed when emailing from a web form using Visual Basic
Hi,
I have a web form which collects data from various text fields and sends it via SMTP to a single recipient. The fields are all in the from msg.Body. Everything works fine but the resultant email is difficult to read because all of information in the email ends up on one or two lines. How can I insert line breaks so that the resultant email is more easily read?
Thanks in advance...
Sample VB Code behind the "Send" button.
Imports System.Net.Mail
Partial Class Registration
Inherits System.Web.UI.Page
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim fromAddress As New MailAddress("sender@somepl ace.com")
Dim toAddress As New MailAddress("recipient@ano therplace. com")
Dim msg As New MailMessage(fromAddress, toAddress)
msg.Subject = " Test MAIL MESSAGE"
msg.Body = "First Name:" + " " + txtFirstName.Text.Trim() + " " + _
txtLastName.Text.Trim() + ", " + txtMI.Text.Trim() _
"Address:" + " " + txtAddress + "City:" + " " + txtCity.Text _
' More code like above
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient
mailSender.Host = "mail.hostname.com"
Try
mailSender.Send(msg)
lblMessage.Text = "Message Sent!"
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
I have a web form which collects data from various text fields and sends it via SMTP to a single recipient. The fields are all in the from msg.Body. Everything works fine but the resultant email is difficult to read because all of information in the email ends up on one or two lines. How can I insert line breaks so that the resultant email is more easily read?
Thanks in advance...
Sample VB Code behind the "Send" button.
Imports System.Net.Mail
Partial Class Registration
Inherits System.Web.UI.Page
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim fromAddress As New MailAddress("sender@somepl
Dim toAddress As New MailAddress("recipient@ano
Dim msg As New MailMessage(fromAddress, toAddress)
msg.Subject = " Test MAIL MESSAGE"
msg.Body = "First Name:" + " " + txtFirstName.Text.Trim() + " " + _
txtLastName.Text.Trim() + ", " + txtMI.Text.Trim() _
"Address:" + " " + txtAddress + "City:" + " " + txtCity.Text _
' More code like above
msg.IsBodyHtml = True
Dim mailSender As New System.Net.Mail.SmtpClient
mailSender.Host = "mail.hostname.com"
Try
mailSender.Send(msg)
lblMessage.Text = "Message Sent!"
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
ASKER
Thanks, I tried it but the result is unchanged.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or if you perfer to send text mail try removing msg.IsBodyHtml = True, and replace it with
msg.BodyEncoding = Encoding.ASCII
msg.BodyFormat = MailFormat.Text
msg.BodyEncoding = Encoding.ASCII
msg.BodyFormat = MailFormat.Text
So
msg.body = "First Name:" + " " + txtFirstName.Text.Trim() + VBCRLF + txtLastName.Text.Trim() + ...
etc.