HOWTO: Accessing SMTP Headers of a Message Using CDO

ID: Q194870


The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.2, 1.21


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 (CDO) 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 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:

Q178073 HOWTO: Obtaining the SMTP Header for a MAPI Message
For additional information on SMTP:
Q87022 SMTP: Definition of SMTP
Microsoft Developer Network Library; search on: "MAPI Property Tags"

Additional query words: Internet

Keywords : kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 4, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.