Word document content into an email

Posted on 2009-02-19
Medium Priority
Last Modified: 2012-05-06
Is there any way to get clean html from a word document in VB.net to make it the body of an email. I can get the html into the body of the email but any special characters(ie. bullets, hyphens) in the word document come out as odd characters in the html like squares and unknown shapes. The code I am using to get the html in the email is below. It works, but has unexpected characters in the html.
Public Function SendEmails(ByVal sEmailFrom As String, ByVal sEmailSubject As String, _
                            ByVal sSMTP As String, ByVal sTo As String, ByVal sCC As String(), _
                            ByVal sFileName As String) As Boolean
        Dim bResult As Boolean = True
        Dim oMessage As New MailMessage(sEmailFrom, sTo)
        Dim oSMTP As New SmtpClient
        oSMTP.Host = sSMTP
        oMessage.Subject = sEmailSubject
        For Each sCCAddress As String In sCC
        oMessage.IsBodyHtml = True
        oMessage.Body = GetWordContent(sFileName)
        Catch ex As Exception
            bResult = False
        End Try
        Return bResult
    End Function
Private Function GetWordContent(ByVal sFileName As String) As String
        Dim sResult As String = String.Empty
            Dim oStream As StreamReader
            oStream = File.OpenText(sFileName)
            sResult = oStream.ReadToEnd
        Catch ex As Exception
        End Try
        Return sResult
    End Function

Open in new window

Question by:Un-Obtainium
1 Comment
LVL 15

Accepted Solution

Praveen Venu earned 2000 total points
ID: 23732056
I think it is simple. Using the below code you can save the Word file into HTML (word builtin option)

then you can read the HTML file and send email

Dim wrdApp As New Word.Application
        Dim wrdDoc As Word.Document = wrdApp.Documents.Open("C:\Test.doc")
        wrdDoc.SaveAs("C:\Test.htm", Word.WdSaveFormat.wdFormatHTML)

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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 video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Suggested Courses

807 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