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
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...
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
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 (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]
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 (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]
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...
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;
}
--
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...