Send word content in an email.

In, what is the easiest way to put the content of a word document into and email and preserve the formatting.
Who is Participating?
Éric MoreauSenior .Net ConsultantCommented:
>>saving the word document as a html document does not change the result. any other suggestions?

if you read the newly saved file as a text file to provide it to your body, it will work. You have to forget the .Content.Text property.
Éric MoreauSenior .Net ConsultantCommented:
you would need to convert it as HTML but it can generate very ugly and not universal HTML.
Un-ObtainiumAuthor Commented:
I have tried the following, but it does not hold the formatting. How do I get the html from the word doc?
Imports System.Net.Mail
Imports Microsoft.Office.Interop
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 oWord As New Word.Application
        Dim oDoc As Word.Document
        oWord.Visible = False
            oDoc = oWord.Documents.Add(sFileName)
            sResult = oDoc.Content.Text
        Catch ex As Exception
        End Try
        Return sResult
    End Function

Open in new window

Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

Éric MoreauSenior .Net ConsultantCommented:
The reason is that Content.Text returns only the text (no formatting).

have a look at
or maybe you can save it as a HTML document (using the SaveAs method of Word)

I use Aspose components to do that kind of transformation:
Un-ObtainiumAuthor Commented:
saving the word document as a html document does not change the result. any other suggestions?
Un-ObtainiumAuthor Commented:
That worked. But like you said in the begining the html produced is not perfect. It does not handle some special characters from the word document.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.