Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
271 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 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

Vim Reference Guide

Vim is a powerful text editor favored by many sysadmins and developers - here are some commands that you'll want to keep in your back pocket!

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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