Outlook - Access mail properties from a custom button .net addin

Asked By John Roa on 21-May-12 06:55 AM
My situation is that my company gets an email from another company with a link to a file that we need to download and then process.  All that is done manually by my users.  i've been tasked with creating a button in Outlook, such that it will read the email looking for a name of the client this needs to be processed for in the subject and also retreive the url in the email so that I can get the file from the web and process it.  Now, barring any freaky permission issues, I know how to down load the file and process it.  My problem is that i've never created an outlook addin before.  i've done a bunch of searching on the web and have created one.  I see the new ribbon on the opened email and even the button that I created.  Now I need to be able to access the subject and body (accessing the From would help me in another project that I see coming down the pike and I'm hoping that how I access the subject and body would be the same methodology).

So, in my ribbon class, I have the following:
Imports Microsoft.Office.Tools.Ribbon

Public Class MyRibbon

Private Sub MyRibbon_Load(Byval sender as System.Object, ByVal e as RibbonUIEventArgs) handles MyBase.Load

End Sub

Private Sub btnProcText_Click(sender as System.Object, e as Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles btnProcText.Click
     What goes here to access the subject and body?
End Sub
End Class

This is all Framework 4.0 and preferrably VB.Net (and not COM) and Outlook 2010 on Windows 7.  
[)ia6l0 iii replied to John Roa on 21-May-12 12:37 PM
Use the ActiveInspector's current item , if the button is on the email template. Sample code would look like below:

Outlook.MailItem mailItem = Outlook.Application.ActiveInspector.CurrentItem as Outlook.MailItem;

You should have the body, subject, recepients as the mailitem object's properties.

Hope this helps.

Jitendra Faye replied to John Roa on 29-May-12 01:07 AM
For reference refer this code-

Public Class ThisAddIn

    Dim olkApp As Outlook.Application, olkSes As Outlook.NameSpace

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
      olkApp = New Outlook.Application
      olkSes = olkApp.GetNamespace("MAPI")
    End Sub

    Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
      olkSes = Nothing
      olkApp = Nothing
    End Sub

    Private Sub ReadMsg()
      Dim olkMsg As Outlook.MailItem, strSubject As String, strMessage As String, strFrom As String, strTo As String
      Select Case TypeName(olkApp.ActiveWindow)
        Case "Explorer"
          olkMsg = olkApp.ActiveExplorer.Selection(1)
        Case "Inspector"
          olkMsg = olkApp.ActiveInspector.CurrentItem
      End Select
      With olkMsg
        strSubject = .Subject
        strMessage = .Body
        strFrom = .SenderName
        strTo = .To
      End With
    End Sub

End Class

Follow this link also-