Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-01
4
Medium Priority
?
278 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 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

824 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