Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDO and MAPI question.

Status
Not open for further replies.

IndigoDragon

Programmer
Aug 2, 2005
57
NL
Hello,

I've been trying to set up a CDO connection to retrieve the senders mail address. The script returns a 'user-defined type not defined' error for the "MAPI" statement. I've added a reference to the "Outlook 10.0 Object Library". The code I used initially I got from MSDevNetwork (MSDN.com) and should work for Office 2002 (Which I'm using.). Here's the code:

Sub GetSender()

' *****************************************
' Get the senders e-mail address using CDO.
' *****************************************

Dim objCDO As MAPI.Session
Dim objMsg As MAPI.Message
Dim objSender As MAPI.AddressEntry
Dim oMsg As Outlook.MailItem
Dim strMsg As String
On Error Resume Next
Set oMsg = Application.ActiveExplorer.Selection.Item(1)
Set objCDO = CreateObject("MAPI.Session")
objCDO.Logon "", "", False, False
Set objMsg = objCDO.GetMessage(oMsg.EntryID)
Set objSender = objMsg.Sender
strMsg = "Subject: " & objMsg.Subject & vbCrLf _
& "Sender Name: " & objSender.Name & vbCrLf _
& "Sender e-mail: " & objSender.Address & vbCrLf _
& "Sender type: " & objSender.Type
MsgBox strMsg, vbInformation

End Sub

-----------------------------------------------------------
Does anyone know what the problem is?
ThanX!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top