Solved

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

Posted on 2009-07-01
4
262 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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: …

746 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

12 Experts available now in Live!

Get 1:1 Help Now