Solved

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

Posted on 2009-07-01
4
263 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
  • 2
  • 2
4 Comments
 
LVL 69

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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

13 Experts available now in Live!

Get 1:1 Help Now