Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem reading e-mail from exchange 2003 programmatically

2 views
Skip to first unread message

bi...@kamrava.com

unread,
Dec 3, 2007, 11:28:50 PM12/3/07
to
Hello all,

I have some programs that uses the code below and does not give me any
problem. However recently I copied the same code and now it generate
error when it hit the line
objInbox = objSession.Inbox
Can someone please give me an alternate method to read e-mails without
using CDO?

The error message is this:

System.Runtime.InteropServices.COMException was caught
ErrorCode=-2147221219
Message="Microsoft Exchange is not available. Either there are
network problems or the Exchange computer is down for maintenance.
[Microsoft Exchange Information Store -
[MAPI_E_FAILONEPROVIDER(8004011D)]]"
Source="Collaboration Data Objects"

Code snippet
--------------------

Dim objSession As MAPI.Session
Dim objInbox As MAPI.Folder
Dim objMessages As MAPI.Messages
Dim objMessage As MAPI.Message
Dim objMsgFilter As MAPI.MessageFilter
Dim objAttachment As MAPI.Attachment
Dim strProfileInfo As String

strProfileInfo = "Exchange.EmailServer" & vbLf & "E-mail
Alias"
objSession = CreateObject("MAPI.Session")
objSession.Logon(ProfileInfo:=strProfileInfo,
ShowDialog:=False)
'reference the messages in the inbox
objInbox = objSession.Inbox 'get the Inbox object
collection
objMessages = objInbox.Messages 'get the messages
object collection
objMsgFilter = objMessages.Filter 'get the Message
Filter object collection
For Each objMessage In objInbox.Messages
If Not objMessage.Unread Then
' Do somthing with the attachement
End If ' objMessage.Unread

Next objMessage

Ken Slovak - [MVP - Outlook]

unread,
Dec 4, 2007, 9:23:30 AM12/4/07
to
CDO 1.21 is not supported for use with managed code.

If you use the Outlook object model you can't use a logon such as
"Exchange.EmailServer" & vbLf & "E-mail Alias". Extended MAPI is C++ or
Delphi only and is also not supported for use with managed code.

You can use a COM wrapper around Extended MAPI such as Redemption
(www.dimastr.com/redemption) for something like that or you have to fall
back on accessing the Exchange server using something like WebDAV. For
information on that you should post to an Exchange development group.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<bi...@kamrava.com> wrote in message
news:681377b3-5a7a-4d7a...@a35g2000prf.googlegroups.com...

bi...@kamrava.com

unread,
Dec 4, 2007, 7:37:54 PM12/4/07
to
On Dec 4, 6:23 am, "Ken Slovak - [MVP - Outlook]" <kenslo...@mvps.org>
wrote:

> CDO 1.21 is not supported for use with managed code.
>
> If you use the Outlook object model you can't use a logon such as
> "Exchange.EmailServer" & vbLf & "E-mail Alias". Extended MAPI is C++ or
> Delphi only and is also not supported for use with managed code.
>
> You can use a COM wrapper around Extended MAPI such as Redemption
> (www.dimastr.com/redemption) for something like that or you have to fall
> back on accessing the Exchange server using something like WebDAV. For
> information on that you should post to an Exchange development group.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm
> > Next objMessage- Hide quoted text -
>
> - Show quoted text -

Ken,

Thanks for your suggestions. The logon parameters I used were generic
in nature. However I'm interested to know if Microsoft is not going to
support CDO, what are they offering instead.
I have a need in managed code to logon to exchange and read e-mails
from it's Inbox.
Is using Redemption code wrapper the only solution?

Thanks,
Bijan

Ken Slovak - [MVP - Outlook]

unread,
Dec 5, 2007, 9:15:08 AM12/5/07
to
CDO was never supported for use with managed code. Plus it was always an
optional installation from the Office CD and not guaranteed to be installed.
In Office 2007 it's not even on the Office CD, you have to download it from
MS and it's functionality is mostly replicated in the new methods and
properties of the Outlook object model. You also should know that CDO is in
deprecation, it most likely will not be available for Outlook 14 whenever
that comes out.

The recommendation from MS for accessing Exchange in the way you want is to
use WebDAV as I said before. I personally use Redemption but if you don't
want to use 3rd party libraries you should use WebDAV. The Exchange
programming groups are the place for questions about working with WebDAV.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


<bi...@kamrava.com> wrote in message
news:2da1aae4-79f8-4934...@e25g2000prg.googlegroups.com...
<snip> > Ken,

Dmitry Streblechenko

unread,
Dec 5, 2007, 1:12:36 PM12/5/07
to
And, if I recall correctly, WebDAV is being deprecated too, and Exchange
Services is the way to go as of Exchange 2007.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:uBEjCl0N...@TK2MSFTNGP03.phx.gbl...

Ken Slovak - [MVP - Outlook]

unread,
Dec 5, 2007, 1:46:31 PM12/5/07
to
Every "best" technique for Exchange access get deprecated regularly, MS
never can make up their minds and of course now the mantra is that "Exchange
is not a development platform" :(

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dmitry Streblechenko" <dmi...@dimastr.com> wrote in message
news:OxHXFH2N...@TK2MSFTNGP02.phx.gbl...

Dmitry Streblechenko

unread,
Dec 5, 2007, 6:06:59 PM12/5/07
to
And the safest bet is to stick with whatever MS uses in its own products
(Outlook). That would be Extended MAPI... Still very much alive and kicking
after being introduced more than 12 years ago.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Ken Slovak - [MVP - Outlook]" <kens...@mvps.org> wrote in message
news:%232edOC3...@TK2MSFTNGP06.phx.gbl...

Ken Slovak - [MVP - Outlook]

unread,
Dec 5, 2007, 5:19:43 PM12/5/07
to
:)

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dmitry Streblechenko" <dmi...@dimastr.com> wrote in message

news:%23WVZlr4...@TK2MSFTNGP06.phx.gbl...

ranjee...@gmail.com

unread,
Jan 17, 2008, 5:08:08 AM1/17/08
to
On Dec 4 2007, 7:23 pm, "Ken Slovak - [MVP - Outlook]"

<kenslo...@mvps.org> wrote:
> CDO 1.21 is not supported for use with managed code.
>
> If you use the Outlook object model you can't use a logon such as
> "Exchange.EmailServer" & vbLf & "E-mail Alias". Extended MAPI is C++ or
> Delphi only and is also not supported for use with managed code.
>
> You can use a COM wrapper around Extended MAPI such as Redemption
> (www.dimastr.com/redemption) for something like that or you have to fall
> back on accessing the Exchange server using something like WebDAV. For
> information on that you should post to an Exchange development group.
>
> --
> Ken Slovak
> [MVP - Outlook]http://www.slovaktech.com
> Author: Professional Programming Outlook 2007
> Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm

It is easy if you are using VC++, use below code in ur program

char *bodybuf=0; unsigned int bodysize=0;
IStream *istream;
hr = imsg->OpenProperty(PR_BODY, &IID_IStream, STGM_READ, 0,
(IUnknown**)&istream);
if (hr==S_OK)
{ AvailableOffline = true;
STATSTG stg = {0};
hr = istream->Stat(&stg,STATFLAG_NONAME);
if (hr==S_OK)
{ bodysize = stg.cbSize.LowPart; // won't bother checking for >2gb
messages!
bodybuf = new char[bodysize+1];
ULONG red; hr = istream->Read(bodybuf, bodysize, &red);
if (hr!=S_OK) bodysize=0;
else if (red<bodysize) bodysize=red;
bodybuf[bodysize]=0;
}

Calanas@discussions.microsoft.com Andre Calanas

unread,
Apr 11, 2008, 1:43:00 AM4/11/08
to
I've had this same problem, any resolution to this?

Dmitry Streblechenko

unread,
Apr 11, 2008, 1:23:32 PM4/11/08
to
Is you app running under the same Windows user identity as the owner of the
mailbox specified in te hcall to Session.Logon?

--

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

-
"Andre Calanas" <Andre Cal...@discussions.microsoft.com> wrote in message
news:6CFACD41-E621-4B60...@microsoft.com...

0 new messages