msoutlook.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem reading e-mail from exchange 2003 programmatically

 
Post new topic   Reply to topic    msoutlook.org Forum Index -> MS Office Outlook
Author Message
bijan



Joined: 04 Dec 2007
Posts: 2

PostPosted: Tue Dec 04, 2007 1:28 am    Post subject: Problem reading e-mail from exchange 2003 programmatically Reply with quote

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

Archived from group: microsoft>public>office>developer>outlook>vba
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Tue Dec 04, 2007 2:23 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

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


wrote in message @a35g2000prf.googlegroups.com...
> 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
Back to top
View user's profile Send private message
bijan



Joined: 04 Dec 2007
Posts: 2

PostPosted: Tue Dec 04, 2007 9:37 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

On Dec 4, 6:23 am, "Ken Slovak - [MVP - Outlook]"
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
>
> wrote in message
>
> @a35g2000prf.googlegroups.com...
>
>
>
> > 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- 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
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Wed Dec 05, 2007 2:15 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

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


wrote in message @e25g2000prg.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
Back to top
View user's profile Send private message
Dmitry Streblechenko



Joined: 12 Aug 2007
Posts: 220

PostPosted: Wed Dec 05, 2007 3:12 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

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]" wrote in message @TK2MSFTNGP03.phx.gbl...
> 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
>
>
> wrote in message
> @e25g2000prg.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
>
>
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Wed Dec 05, 2007 6:46 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

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" Sad

--
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" wrote in message @TK2MSFTNGP02.phx.gbl...
> 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
Back to top
View user's profile Send private message
Dmitry Streblechenko



Joined: 12 Aug 2007
Posts: 220

PostPosted: Wed Dec 05, 2007 8:06 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

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]" wrote in message
news:%232edOC3NIHA.3852@TK2MSFTNGP06.phx.gbl...
> 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" Sad
>
> --
> 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" wrote in message
> @TK2MSFTNGP02.phx.gbl...
>> 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
>
Back to top
View user's profile Send private message
Ken Slovak - [MVP - Outlo



Joined: 12 Aug 2007
Posts: 405

PostPosted: Wed Dec 05, 2007 10:19 pm    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

Smile

--
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" wrote in message
news:%23WVZlr4NIHA.4476@TK2MSFTNGP06.phx.gbl...
> 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
Back to top
View user's profile Send private message
ranjeet.knit



Joined: 17 Jan 2008
Posts: 1

PostPosted: Thu Jan 17, 2008 7:08 am    Post subject: Re: Problem reading e-mail from exchange 2003 programmatical Reply with quote

On Dec 4 2007, 7:23 pm, "Ken Slovak - [MVP - Outlook]"
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
>
> wrote in message
>
> @a35g2000prf.googlegroups.com...> 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

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 bodybuf[bodysize]=0;
}

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Programmatically select a signature when (programmatically) ....draft I’m using VB6 and Outlook 2002. How do I select a signature for a created draft? Is this even possible? TechNet has an article, but I could not get the signature I wanted, to be inserted in the draft I’m cre

Email1DisplayName Read-Only in Exchange 2003?? Hi I have some Outlook forms that were developed to run against Exchange 5.5. We are migrating to Exchange 2003 and i am conducting testing on these forms in the new environment. I recieved an error that is read only when I test agains

Tabular Data Trashed When Forwarding Programmatically I receive RTF formated emails that contain tabular data. To parse them I forward them to myself as HTML then user MS HTML and Internet controls to extract the table data. After upgrading to Office 2007 I discovered that the tablular data is getting trashe

Programmatically determine wheher I have received a meeting Hi, I am a delegate of my manager, which means I am getting all 'his' meeting requests in my inbox. However I am just a backup person, so therefore I am not the one who is usually accepting the requests. Is there any way to determine whether I have receiv

Programmatically create an Outlook Personal Address book? Is it possible to create an Outlook Personal Address book in VBA? Or any other type of address book that can be viewed locally. Thanks Scott
Post new topic   Reply to topic    msoutlook.org Forum Index -> MS Office Outlook All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group