Article ID: 194870 - Last Review: May 19, 2005 - Revision: 3.0

How to access SMTP headers of a message using CDO (1.x)

This article was previously published under Q194870
Expand all | Collapse all

SUMMARY

This article demonstrates how to get the Internet headers from a SMTP (Simple Mail Transfer Protocol) message received from the Internet using Collaboration Data Objects (1.2, 1.21) and Visual Basic.

MORE INFORMATION

This can be done by using the fields collection of the message and displaying the value of the CdoPR_TRANSPORT_MESSAGE_HEADERS property, which contains the SMTP header information for a Internet mail message. This sample assumes that you already have a message received from the Internet titled "Test Internet message" in your Inbox.

Copy and paste the following code into a Visual Basic project which references the Collaboration Data Objects (1.2, 1.21) library:
    Private Sub Form_Load()

      Dim oSession As MAPI.Session
      Dim oFolder As Folder
      Dim oMsgColl As Messages
      Dim oMessage As Message

      ' Logon to the MAPI session
      Set oSession = New MAPI.Session
      oSession.Logon

      ' Get the Inbox folder and its message collection.
      Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)
      Set oMsgColl = oFolder.Messages

      ' Search through the messages in the Inbox for the Internet
      ' message.  Then use the CdoPR_TRANSPORT_MESSAGE_HEADERS
      ' (&H7D001E) property tag to retrieve the Internet header.
      ' If the property doesn't exist(Not a Internet message) you will
      ' receive a MAPI_E_NOT_FOUND error.

      For Each oMessage In oMsgColl
         If oMessage.Subject = "Test Internet message" Then
              MsgBox oMessage.Fields(&H7D001E) 'Display the header
         End If
      Next

      ' Logoff and cleanup
      oSession.Logoff
      Set oSession = Nothing
      Set oMessage = Nothing
      Set oMsgColl = Nothing
      Set oFolder = Nothing

    End Sub
				

REFERENCES

For an example of how to access the SMTP header when using Visual C++, please see the following article in the Microsoft Knowledge Base:
178073  (http://support.microsoft.com/kb/178073/EN-US/ ) How To Obtaining the SMTP Header for a MAPI Message
For additional information on SMTP:
87022  (http://support.microsoft.com/kb/87022/EN-US/ ) SMTP: Definition of SMTP
Microsoft Developer Network Library; search on: "MAPI Property Tags"

APPLIES TO
  • Microsoft Collaboration Data Objects 1.21
  • Microsoft Collaboration Data Objects 1.2
Keywords: 
kbhowto kbmsg KB194870
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations