Solved

How to handle issues with format of body of email message sent by Windows Forms

Posted on 2009-07-01
4
269 Views
Last Modified: 2013-11-08
Hi,
In a Windows Forms app written in VS2008 / .Net Framework 3.5 I get some data from a database and send it in an email as shown in code below. The mail client is always Outlook 2007 and the message arrives as plain text, but the carriage returns in my string sBody aren't recognised so the text in the message body reads as one very long line. If I show my string sBody in a message box all the carriage returns are there.
Any advice on how to get around this?

Thx

Louise
Dim sBody As String = Me.rtbMsgBody1.Text
            sBody += vbCrLf
            sBody += sMobTel & vbCrLf
            sBody += sHomeTel & vbCrLf
            sBody += sECN & vbCrLf
            sBody += sECR & vbCrLf
            sBody += sECTel1 & vbCrLf
            sBody += sECTel2 & vbCrLf
            sBody += Me.rtbMsgBody2.Text & vbCrLf
 
            Dim objMsg As New System.Net.Mail.MailMessage("administrator@mycompany.com", sEmail, "Your details", sBody)
            With objMsg
                .To.Add(sEmail)
                .From = New System.Net.Mail.MailAddress("administrator@mycompany.com")
                .Subject = sSubject
                .Body = sBody
            End With
 
            Dim objMail As New System.Net.Mail.SmtpClient("IPAddress")
            objMail.Send(objMsg)

Open in new window

0
Comment
Question by:louise001
[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
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24753726
When you view your e-mail in Outlook, do you see a bar at the top of your e-mail saying that extra carriage returns have been removed? You can't do much for this (there may be a setting in Outlook to prevent this).

You can send a HTML body instead of plain text and it will keep formatting. Have a look at http://www.emoreau.com/Entries/Articles/2007/09/Using-SystemNetMail.aspx
0
 

Author Comment

by:louise001
ID: 24754181
Ah, yes I do see that message in Outlook. I can format the message body as HTML fine, but do you know how then I could get data from my datarow into the HTML? Perhaps the answer is to use an ASP.Net app in this case, which I could do, but there may be times when I can't do that but also need to send data in an email message.

Thx

Louise
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 24754506
You don't have to use ASP.Net to create a HTML body!

Dim sBody As String = Me.rtbMsgBody1.Text
            sBody += "<br/>"
            sBody += sMobTel & "<br/>"
            sBody += sHomeTel & "<br/>"
            sBody += sECN & "<br/>"
            sBody += sECR & "<br/>"
            sBody += sECTel1 & "<br/>"
            sBody += sECTel2 & "<br/>"
            sBody += Me.rtbMsgBody2.Text &"<br/>"
0
 

Author Closing Comment

by:louise001
ID: 31598743
Marvellous. Your re-write works perfectly with of course objMsg.IsBodyHTML = True

Thanks very much + enjoy the rest of your day,

Louise
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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