none
How to read Outlook Email Internet header using vc++?? RRS feed

  • Question

  • Hi,

    I want to read Outlook Email internet header using vc++ and have to check ,is there Spam Flag in that.I am unable to find information regarding this...Can any one please tell me.

    Thanks.

    Wednesday, November 23, 2016 1:15 PM

Answers

  • Hello Raji,

    The GetProperty method of the PropertyAccessor class which returns an Object that represents the value of the property specified by SchemaName can help.  

    The Outlook object model is common for all programming languages. You just need to correct the syntax.

    C#

    void DemoPropertyAccessorGetProperty()
        {
            string EntryID = "";
            // SchemaName for PR_TRANSPORT_MESSAGE_HEADERS
            string SchemaTransportHeader =
                @"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
            string filter = "@SQL=" + "Not(" 
                + "\"" + SchemaTransportHeader + "\"" + " Is Null)";
            Outlook.Table tbl = m_olApp.Session.GetDefaultFolder(
                Outlook.OlDefaultFolders.olFolderInbox).GetTable(
                filter, Outlook.OlTableContents.olUserItems);
            if (tbl.GetRowCount() > 0)
            {
                Outlook.Row oRow = tbl.GetNextRow();
                EntryID = oRow["EntryID"].ToString();
            }
            else
            {
                MessageBox.Show("No messages found with Transport Header.", 
                    "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // Get MailItem using GetItemFromID.
            Outlook.MailItem oMail =
                (Outlook.MailItem)
                m_olApp.Session.GetItemFromID(EntryID, Type.Missing );
            // Obtain an instance of PropertyAccessor class.
            Outlook.PropertyAccessor oPA = oMail.PropertyAccessor;
            string Transport = (string)oPA.GetProperty(SchemaTransportHeader);
            // Call GetProperty.
            MessageBox.Show(this, Transport,
                "Transport Header: " + oMail.Subject);
        }

    VB.NET

    Sub DemoPropertyAccessorGetProperty()
        Dim EntryID As String = ""
        ' SchemaName for PR_TRANSPORT_MESSAGE_HEADERS
        Dim SchemaTransportHeader As String = _
        "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
        Dim filter As String = "@SQL=" & "Not(" & Chr(34) _
        & SchemaTransportHeader & Chr(34) & " Is Null)"
        Dim tbl As Outlook.Table = m_olApp.Session.GetDefaultFolder( _
            Outlook.OlDefaultFolders.olFolderInbox).GetTable( _
        filter, Outlook.OlTableContents.olUserItems)
        If tbl.GetRowCount > 0 Then
            Dim oRow As Outlook.Row = tbl.GetNextRow()
            EntryID = oRow("EntryID").ToString()
        Else
            MessageBox.Show("No messages found with Transport Header.", _
               "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        ' Get MailItem using GetItemFromID.
        Dim oMail As Outlook.MailItem = _
            CType(m_olApp.Session.GetItemFromID(EntryID), Outlook.MailItem)
        ' Obtain an instance of PropertyAccessor class.
        Dim oPA As Outlook.PropertyAccessor = oMail.PropertyAccessor
        Dim Transport As String = _
        CType(oPA.GetProperty(SchemaTransportHeader), String)
        ' Call GetProperty.
        MessageBox.Show(Me, Transport, _
            "Transport Header: " & oMail.Subject)
    End Sub

    You may find the following links helpful:

    How to automate Outlook 2010 by using C++ in Visual Studio 2010 together with MFC

    C++ app automates Outlook (CppAutomateOutlook)

    Also you may find the Understanding the Safe and Blocked Senders lists page helpful. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Chenchen LiModerator Friday, November 25, 2016 10:08 AM
    • Marked as answer by Rajiuser1 Wednesday, November 30, 2016 5:55 AM
    Wednesday, November 23, 2016 2:05 PM

All replies

  • Hello Raji,

    You may get PR_TRANSPORT_MESSAGE_HEADERS property of the message. This property would include all transport headers which you may parse to find the flag you are interested in.

    Hope this helps,


    Slava Ivanov

    Wednesday, November 23, 2016 1:50 PM
  • Hello Raji,

    The GetProperty method of the PropertyAccessor class which returns an Object that represents the value of the property specified by SchemaName can help.  

    The Outlook object model is common for all programming languages. You just need to correct the syntax.

    C#

    void DemoPropertyAccessorGetProperty()
        {
            string EntryID = "";
            // SchemaName for PR_TRANSPORT_MESSAGE_HEADERS
            string SchemaTransportHeader =
                @"http://schemas.microsoft.com/mapi/proptag/0x007D001E";
            string filter = "@SQL=" + "Not(" 
                + "\"" + SchemaTransportHeader + "\"" + " Is Null)";
            Outlook.Table tbl = m_olApp.Session.GetDefaultFolder(
                Outlook.OlDefaultFolders.olFolderInbox).GetTable(
                filter, Outlook.OlTableContents.olUserItems);
            if (tbl.GetRowCount() > 0)
            {
                Outlook.Row oRow = tbl.GetNextRow();
                EntryID = oRow["EntryID"].ToString();
            }
            else
            {
                MessageBox.Show("No messages found with Transport Header.", 
                    "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            // Get MailItem using GetItemFromID.
            Outlook.MailItem oMail =
                (Outlook.MailItem)
                m_olApp.Session.GetItemFromID(EntryID, Type.Missing );
            // Obtain an instance of PropertyAccessor class.
            Outlook.PropertyAccessor oPA = oMail.PropertyAccessor;
            string Transport = (string)oPA.GetProperty(SchemaTransportHeader);
            // Call GetProperty.
            MessageBox.Show(this, Transport,
                "Transport Header: " + oMail.Subject);
        }

    VB.NET

    Sub DemoPropertyAccessorGetProperty()
        Dim EntryID As String = ""
        ' SchemaName for PR_TRANSPORT_MESSAGE_HEADERS
        Dim SchemaTransportHeader As String = _
        "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
        Dim filter As String = "@SQL=" & "Not(" & Chr(34) _
        & SchemaTransportHeader & Chr(34) & " Is Null)"
        Dim tbl As Outlook.Table = m_olApp.Session.GetDefaultFolder( _
            Outlook.OlDefaultFolders.olFolderInbox).GetTable( _
        filter, Outlook.OlTableContents.olUserItems)
        If tbl.GetRowCount > 0 Then
            Dim oRow As Outlook.Row = tbl.GetNextRow()
            EntryID = oRow("EntryID").ToString()
        Else
            MessageBox.Show("No messages found with Transport Header.", _
               "Demo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Exit Sub
        End If
        ' Get MailItem using GetItemFromID.
        Dim oMail As Outlook.MailItem = _
            CType(m_olApp.Session.GetItemFromID(EntryID), Outlook.MailItem)
        ' Obtain an instance of PropertyAccessor class.
        Dim oPA As Outlook.PropertyAccessor = oMail.PropertyAccessor
        Dim Transport As String = _
        CType(oPA.GetProperty(SchemaTransportHeader), String)
        ' Call GetProperty.
        MessageBox.Show(Me, Transport, _
            "Transport Header: " & oMail.Subject)
    End Sub

    You may find the following links helpful:

    How to automate Outlook 2010 by using C++ in Visual Studio 2010 together with MFC

    C++ app automates Outlook (CppAutomateOutlook)

    Also you may find the Understanding the Safe and Blocked Senders lists page helpful. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Proposed as answer by Chenchen LiModerator Friday, November 25, 2016 10:08 AM
    • Marked as answer by Rajiuser1 Wednesday, November 30, 2016 5:55 AM
    Wednesday, November 23, 2016 2:05 PM
  • Thank you...
    Wednesday, November 23, 2016 2:43 PM
  • Hi,

    I suggest you mark helpful reply as answer if your issue has been resolved.

    Thanks for your understanding.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 28, 2016 11:13 AM
    Moderator