Solved

How to insert a line feed when emailing from a web form using Visual Basic

Posted on 2006-10-25
4
179 Views
Last Modified: 2008-02-01
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@someplace.com")
        Dim toAddress As New MailAddress("recipient@anotherplace.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
0
Comment
Question by:cbdrako99
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Xeavn
ID: 17807798
Try using VBCRLF

So

msg.body = "First Name:" + " " + txtFirstName.Text.Trim() + VBCRLF + txtLastName.Text.Trim() + ...

etc.

0
 

Author Comment

by:cbdrako99
ID: 17807937
Thanks,  I tried it but the result is unchanged.
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 125 total points
ID: 17808474
try using environment.newline instead of VBCRLF. if thats not working, maybe you are sending in HTML format, in which case try adding "<br/>" or enclose the paragraphs in "<p></p>" codes.

msg.body = "First Name:" + " " + txtFirstName.Text.Trim() + "<br/> " + txtLastName.Text.Trim() + ...

or

msg.body = "<p>First Name:" + " " + txtFirstName.Text.Trim() + "</p> <p>" + txtLastName.Text.Trim() + "</p>...
0
 
LVL 4

Expert Comment

by:Xeavn
ID: 17812584
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now