Word document content into an email

Posted on 2009-02-19
Last Modified: 2012-05-06
Is there any way to get clean html from a word document in 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

    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

    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

    Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
    This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
    This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now