none
Reading email in outlook with c# and parsing the body RRS feed

  • Question

  • Hello,

    I don't know where to start.

    The organization I work for uses different user web forms to collect user/client feedback. Instead of having those forms populate a table, they have them emailed to me as text in the body of an email for me to decide what to do with. My (local) boss wants me to upload the data into our CRM. Everyone expects me to do that by hand ( which is now getting out of hand :D.)

    I need to read an outlook 2010 email in a shared mailbox (to which I do not know the account password for mail server access) and parse the body data into a data table. 

    If I can get some help understanding how to access the individual email file(s) and read the data into a string array or something that achieves this result, I can take it from there.  All suggestions are welcome however going back to the admin who is in another country, won't make changes and doesn't speak english are not paths I can follow.

    My glass here, is half full with the opportunity to resolve this challenge. 

    • Moved by CoolDadTx Wednesday, April 22, 2015 5:43 PM Office related
    Wednesday, April 22, 2015 4:38 PM

Answers

  • Hello,

    You can develop a VBA macro for handling new emails in the shared mailbox. I'd suggest starting from the Getting Started with VBA in Outlook 2010 article. If you see a shared mailbox in your Outlook profile you can subscribe to the Inbox events (for example, ItemAdd) in the following way:

    Dim WithEvents myInboxMailItem As Outlook.Items
     
    Private Sub myInboxMailItem_ItemAdd(ByVal Item As Object)
         Call MsgBox("Item Added", vbOKOnly, "SharedMailBox@domain.com")
     End Sub
     
    Private Sub Initialize_Handler()
     Dim fldInbox As Outlook.MAPIFolder
     Dim gnspNameSpace As Outlook.NameSpace
         Set gnspNameSpace = Outlook.GetNamespace("MAPI") 'Outlook Object
         Set fldInbox = gnspNameSpace.Folders("SharedMailBox@domain.com").Folders("Inbox")
         Set myInboxMailItem = fldInbox.Items
     End Sub
     
    Private Sub Application_Startup()
         Call Initialize_Handler
     End Sub

    In the ItemAdd event handler you can get all the required information parse the message body. The Outlook object model provides  three main ways for working with item bodies: Body, HTMLBody and WordEditor.
    Wednesday, April 22, 2015 5:54 PM
  • Hi SMX867,

    First, please refer to Eugene’s reply.

    Secondly, if you don’t familiar with VBA, you could create an outlook add-in project and use C# to achieve that.

    # Creating Your First Application-Level Add-in for Outlook

    https://msdn.microsoft.com/en-us/library/cc668191.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 23, 2015 7:34 AM
    Moderator

All replies

  • Hello,

    You can develop a VBA macro for handling new emails in the shared mailbox. I'd suggest starting from the Getting Started with VBA in Outlook 2010 article. If you see a shared mailbox in your Outlook profile you can subscribe to the Inbox events (for example, ItemAdd) in the following way:

    Dim WithEvents myInboxMailItem As Outlook.Items
     
    Private Sub myInboxMailItem_ItemAdd(ByVal Item As Object)
         Call MsgBox("Item Added", vbOKOnly, "SharedMailBox@domain.com")
     End Sub
     
    Private Sub Initialize_Handler()
     Dim fldInbox As Outlook.MAPIFolder
     Dim gnspNameSpace As Outlook.NameSpace
         Set gnspNameSpace = Outlook.GetNamespace("MAPI") 'Outlook Object
         Set fldInbox = gnspNameSpace.Folders("SharedMailBox@domain.com").Folders("Inbox")
         Set myInboxMailItem = fldInbox.Items
     End Sub
     
    Private Sub Application_Startup()
         Call Initialize_Handler
     End Sub

    In the ItemAdd event handler you can get all the required information parse the message body. The Outlook object model provides  three main ways for working with item bodies: Body, HTMLBody and WordEditor.
    Wednesday, April 22, 2015 5:54 PM
  • Hi SMX867,

    First, please refer to Eugene’s reply.

    Secondly, if you don’t familiar with VBA, you could create an outlook add-in project and use C# to achieve that.

    # Creating Your First Application-Level Add-in for Outlook

    https://msdn.microsoft.com/en-us/library/cc668191.aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 23, 2015 7:34 AM
    Moderator