[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2006-10-25
4
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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