Microsoft KB Archive/194870

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

Article ID: 194870

Article Last Modified on 5/19/2005

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.21
 * Microsoft Collaboration Data Objects 1.2

-



This article was previously published under Q194870



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

