none
Deleting from Mail Body RRS feed

  • Question

  • I am looking to setup a string of the entire mailbody. But looking to remove everything from the <table> tag all the way down through the rest of the mail. Is there a way to do this?
    Friday, March 4, 2016 4:36 PM

Answers

  • Hello,

    Looks like you just need to parse the HTML markup of the message body. You can use the HTMLBody property of the MailItem class to get the HTML markup and do whatever you need. Then you can assign it back.

    • Marked as answer by David_JunFeng Sunday, March 13, 2016 1:07 PM
    Friday, March 4, 2016 6:00 PM
  • >>>I am looking to setup a string of the entire mailbody. But looking to remove everything from the <table> tag all the way down through the rest of the mail. Is there a way to do this?

    According to your description, please correct me if I have any misunderstandings on your question, you could refer to below code:

    Tools->References, then add "Microsoft HTML Object Library" reference

    Sub DemoHtmlTables()
        
        Dim oMail As MailItem
        
        Set oMail = Application.ActiveInspector.currentItem
        ' get html table from email object
        Dim oHTML As MSHTML.HTMLDocument: Set oHTML = New MSHTML.HTMLDocument
        Dim oElColl As MSHTML.IHTMLElementCollection
    
        With oHTML
            .Body.innerHTML = oMail.HTMLBody
            Debug.Print .Body.innerHTML
            Set oElColl = .getElementsByTagName("table")
        End With
    
        Set myNode = oElColl.item(0)
        Do While (Not myNode.FirstChild Is Nothing)
           myNode.RemoveChild (myNode.FirstChild)
        Loop
    
        Debug.Print oHTML.Body.innerHTML
        
    End Sub
    

    In addition could you provide more information about your issue, for example sample code and screenshot, that will help us resolve it.

    Thanks for your understanding.

    • Marked as answer by David_JunFeng Sunday, March 13, 2016 1:07 PM
    Monday, March 7, 2016 5:19 AM

All replies

  • Hello,

    Looks like you just need to parse the HTML markup of the message body. You can use the HTMLBody property of the MailItem class to get the HTML markup and do whatever you need. Then you can assign it back.

    • Marked as answer by David_JunFeng Sunday, March 13, 2016 1:07 PM
    Friday, March 4, 2016 6:00 PM
  • >>>I am looking to setup a string of the entire mailbody. But looking to remove everything from the <table> tag all the way down through the rest of the mail. Is there a way to do this?

    According to your description, please correct me if I have any misunderstandings on your question, you could refer to below code:

    Tools->References, then add "Microsoft HTML Object Library" reference

    Sub DemoHtmlTables()
        
        Dim oMail As MailItem
        
        Set oMail = Application.ActiveInspector.currentItem
        ' get html table from email object
        Dim oHTML As MSHTML.HTMLDocument: Set oHTML = New MSHTML.HTMLDocument
        Dim oElColl As MSHTML.IHTMLElementCollection
    
        With oHTML
            .Body.innerHTML = oMail.HTMLBody
            Debug.Print .Body.innerHTML
            Set oElColl = .getElementsByTagName("table")
        End With
    
        Set myNode = oElColl.item(0)
        Do While (Not myNode.FirstChild Is Nothing)
           myNode.RemoveChild (myNode.FirstChild)
        Loop
    
        Debug.Print oHTML.Body.innerHTML
        
    End Sub
    

    In addition could you provide more information about your issue, for example sample code and screenshot, that will help us resolve it.

    Thanks for your understanding.

    • Marked as answer by David_JunFeng Sunday, March 13, 2016 1:07 PM
    Monday, March 7, 2016 5:19 AM