none
Identifying HTML Table in sent email RRS feed

  • Question

  •  I want to parse an embedded table in an email.  Once i sent an outlook email i want to parse this table and save its data to a database.  Any ideas how i can implement this?  Thanks
    Monday, December 30, 2013 10:17 AM

Answers

  • Hi SMZ83,

    As I wrote you above, you can utilize the Word Object Model if the Inspector window is opened. The Inspector class provides the WordEditor property which returns the Microsoft Word Document Object Model of the message being displayed. For example:

    Word.Document appointmentItemDocument = inspector.WordEditor as Word.Document;

    Also you can use the Body (returns a string without formatting) and HTMLBody properties. The latter returns an HTML markup that could be passed in the code of your add-in.

    Please read more about possible ways of parsing the Body in the Chapter 17: Working with Item Bodies.

    • Marked as answer by Safwan Mzah Wednesday, January 1, 2014 12:41 PM
    Monday, December 30, 2013 1:06 PM

All replies

  • Hello SMZ83,

    There are two possible solutions in your case:

    1. You can use the ItemSend event of the Application class from the Outlook Object Model. Note, it is fired right after you click the "Send" button and before the mail is sent. So, you can cancel the sending process setting the Cancel argument to true.

    2. The MailItem class provides the SaveSentMessageFolder property which returns an instance of the Folder class which represents the folder in which a copy of the e-mail message will be saved after being sent. So, you can handle the ItemAdd event of the collection of items of the folder returned by the SaveSentMessageFolder property. The standard folder which stores all sent messages by default is "Sent Items". You can get it by using the following code:

    Outlook.NameSpace ns = OutlookApp.GetNamespace("MAPI");
    Outlook.Folder sentFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) as Outlook.Folder; 

    The Folder class provides the Items property which represents a collection of Outlook items in the specified folder. The Items class provides the ItemAdd event which occurs when one or more items are added to the specified collection. Note, the event doesn't run when a large number of items are added to the folder at once.

    Which way is to choose depends on your needs.

    To get the required data you can use the Body or HTMLBody properties of the MailItem class. Note, you can utilize the Word Object Model if the Inspector window is opened. The Inspector class provides the WordEditor property which returns the Microsoft Word Document Object Model of the  message being displayed.



    Monday, December 30, 2013 10:53 AM
  • Hello,

    Thank you for your reply.

    I think i will use the ItemSend and the Send method for an Outlook item, in a program.
    (
    An outlook add-in )
    This link is detailing this step:
    http://msdn.microsoft.com/en-us/library/office/ff865634.aspx

    To get the email body i will use the Body or HTMLBody properties of the MailItem class.
    Normally, after this step i would retrieve the whole email body content. That is: text + table + images...

    Do you know any clue to get just the content of <table> object within this body?

    My goal, is to be able to identify table data from the email body and send the data to corresponding fields in the database.
    The challenge also is to have a flexible way to read the table data from different emails.

    Example:
    Email 1 (with
    subject 1) will contain table 1 having specific structure or columns, so the identification of the table 1 will include 2 steps
    parsing or recognition of the table data regarding this email (table 1 for email 1) then from the data base perspective: say the data of table should be
    validated with the data definition of table 1 in the db.


    Email 2 (with subject 2) will contain table 2 ... and the same logic.

    I hope it is clear and thanking you in advance for your help.

    Monday, December 30, 2013 12:37 PM
  • Hi SMZ83,

    As I wrote you above, you can utilize the Word Object Model if the Inspector window is opened. The Inspector class provides the WordEditor property which returns the Microsoft Word Document Object Model of the message being displayed. For example:

    Word.Document appointmentItemDocument = inspector.WordEditor as Word.Document;

    Also you can use the Body (returns a string without formatting) and HTMLBody properties. The latter returns an HTML markup that could be passed in the code of your add-in.

    Please read more about possible ways of parsing the Body in the Chapter 17: Working with Item Bodies.

    • Marked as answer by Safwan Mzah Wednesday, January 1, 2014 12:41 PM
    Monday, December 30, 2013 1:06 PM