Insert word file content into Outlook email body

Marcelo Nogueira 20 Reputation points
2023-10-31T12:18:39.8866667+00:00

Good morning!! I need to create an email sending routine in my code in Vb.net where the content in the word file would be included in the body of the email.

Thank you very much in advance.

Developer technologies | VB
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-10-31T13:38:15.0733333+00:00

    Hi @Marcelo Nogueira ,

    Please check if the following code example helps.

    Imports Microsoft.Office.Interop.Outlook
    Imports Microsoft.Office.Interop.Word
    
    Public Class MainForm
        Private Sub btnSendEmail_Click(sender As Object, e As EventArgs) Handles btnSendEmail.Click
            Dim outlookApp As Outlook.Application = New Outlook.Application()
            Dim mailItem As Outlook.MailItem = outlookApp.CreateItem(Outlook.OlItemType.olMailItem)
    
            mailItem.To = "recipient@example.com"
            mailItem.Subject = "Subject of the email"
    
            Dim wordApp As Word.Application = New Word.Application()
            Dim doc As Word.Document = wordApp.Documents.Open("C:\path\to\your\document.docx")
    
            mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
            mailItem.Body = doc.Content.Text
            mailItem.Display(False)
    
            Marshal.ReleaseComObject(doc)
            Marshal.ReleaseComObject(wordApp)
            Marshal.ReleaseComObject(mailItem)
            Marshal.ReleaseComObject(outlookApp)
        End Sub
    End Class
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.