CDO Open Mailbox

B

Bob Smith

I posted this in the VBScript forum, but have not recieved a response. I was
wondering if anyone had an example of how to connect to a mailbox (exchange
2003) via VBScript using CDO. I am looking to enumerate through the items int
he inbox and perform some tasks. I just need a starting point, as I have not
used CDO for anything but sending messages int he past.
 
K

Ken Slovak - [MVP - Outlook]

For CDO 1.21 you really want to explore the www.cdolive.com Web site. It has
tons of CDO sample code plus various property tags including lots of
undocumented property tags.

Where is this code running, a form with VBScript or in Outlook VBA? This
sample is VBA style, just comment out the As clauses to make it VBScript
compatible:

Dim oSession As MAPI.Session
Set oSession = CreateObject("MAPI.Session")

oSession.Logon "", "", False, False

' Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder As MAPI.Folder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim colMessages As MAPI.Messages
Set colMessages = oFolder.Messages

Dim oMessage As MAPI.Message

For Each oMessage In colMessages
'whatever
Next
 
B

Bob Smith

Thanks for your help.

I was able to connect to a mailbox using VBscript with a machine that is
running outlook. The problem is however I need to do this on a machine that
does not run outlook. The machine I need to get this working on does not have
outlook installed, only the exchange system tools (2003 SP2). I recieve the
following error;

C:\temp\connectMailBox.vbs(7, 2) Collaboration Data Objects: [Collaboration
Dat
a Objects - [MAPI_E_LOGON_FAILED(80040111)]]

I checked CDOLive and couldn't see how to egt CD working on a machine.
 
K

Ken Slovak - [MVP - Outlook]

It's the logon.

The logon arguments "", "", False, False can only be used when a MAPI
session is already running (Outlook is running). Otherwise you have to
specify a profile to use or start a profile logon dialog.

On http://www.cdolive.com/cdo5.htm look at the "Log on, send a message and
log off" section. That shows how to use different logons depending on
existing conditions.




Bob Smith said:
Thanks for your help.

I was able to connect to a mailbox using VBscript with a machine that is
running outlook. The problem is however I need to do this on a machine
that
does not run outlook. The machine I need to get this working on does not
have
outlook installed, only the exchange system tools (2003 SP2). I recieve
the
following error;

C:\temp\connectMailBox.vbs(7, 2) Collaboration Data Objects:
[Collaboration
Dat
a Objects - [MAPI_E_LOGON_FAILED(80040111)]]

I checked CDOLive and couldn't see how to egt CD working on a machine.

Ken Slovak - said:
For CDO 1.21 you really want to explore the www.cdolive.com Web site. It
has
tons of CDO sample code plus various property tags including lots of
undocumented property tags.

Where is this code running, a form with VBScript or in Outlook VBA? This
sample is VBA style, just comment out the As clauses to make it VBScript
compatible:

Dim oSession As MAPI.Session
Set oSession = CreateObject("MAPI.Session")

oSession.Logon "", "", False, False

' Const CdoDefaultFolderInbox = 1 ' uncomment for VBScript code

Dim oFolder As MAPI.Folder
Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)

Dim colMessages As MAPI.Messages
Set colMessages = oFolder.Messages

Dim oMessage As MAPI.Message

For Each oMessage In colMessages
'whatever
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top