Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Exchange
2000.active.directory
2000.admin
2000.announcements
2000.app.conversion
2000.applications
2000.clients
2000.clustering
2000.connectivity
2000.development
2000.documentation
2000.general
2000.information.store
2000.interop
2000.kms
2000.misc
2000.protocols
2000.realtime.collabo.
2000.setup
2000.transport
2000.win2000
admin
application.conversion
applications
clients
clustering
connectivity
design
development
misc
mobility
setup
tools
  
 
date: Mon, 19 Dec 2005 13:41:20 -0800,    group: microsoft.public.exchange2000.development        back       


Retrieving message attachments using ExOLEDB   
I'm working on a project to archive messages from a specific mailbox in 
Exchange and store the information in a database.  I have something like:

' Open the connection to the Exchange message store using ExOLEDB
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ExOLEDB.DataSource"
surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user & 
"/Inbox"
Conn.Open sUrl

Dim Rs
Set Rs = CreateObject("ADODB.Recordset")

' SQL to return the desired fields from the Exchange server
Dim sql
sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"", 
""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"", 
""urn:schemas:httpmail:subject"", ""urn:schemas:httpmail:textdescription"", 
""urn:schemas:mailheader:message-id"", 
""urn:schemas:httpmail:attachmentfilename"" from"
sql = sql & " scope('shallow traversal of """ & sUrl & """')"
sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = False"

Everything is as expected here EXCEPT the 
urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty regardless 
of whether the message has an attachment or not.

Question: What is the proper method to get the attachment so that I can 
store it away?

Thanks...
date: Mon, 19 Dec 2005 13:41:20 -0800   author:   jwh20

Re: Retrieving message attachments using ExOLEDB   
Your better of using CDOEX to process attachments, CDOEX still uses Exoledb 
as the means of accessing the store but gives you some better interfaces for 
manipulating messages. see 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_ibodypart_filename.asp 
and also 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_extracting_embedded_messages.asp

Cheers
Glen

"jwh20"  wrote in message 
news:D8F49AD0-5CB1-45FA-80AC-F5ABBF035211@microsoft.com...
> I'm working on a project to archive messages from a specific mailbox in
> Exchange and store the information in a database.  I have something like:
>
> ' Open the connection to the Exchange message store using ExOLEDB
> Set Conn = CreateObject("ADODB.Connection")
> Conn.Provider = "ExOLEDB.DataSource"
> surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user &
> "/Inbox"
> Conn.Open sUrl
>
> Dim Rs
> Set Rs = CreateObject("ADODB.Recordset")
>
> ' SQL to return the desired fields from the Exchange server
> Dim sql
> sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"",
> ""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"",
> ""urn:schemas:httpmail:subject"", 
> ""urn:schemas:httpmail:textdescription"",
> ""urn:schemas:mailheader:message-id"",
> ""urn:schemas:httpmail:attachmentfilename"" from"
> sql = sql & " scope('shallow traversal of """ & sUrl & """')"
> sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = False"
>
> Everything is as expected here EXCEPT the
> urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty 
> regardless
> of whether the message has an attachment or not.
>
> Question: What is the proper method to get the attachment so that I can
> store it away?
>
> Thanks...
date: Tue, 20 Dec 2005 09:59:02 +1100   author:   Glen Scales [MVP]

Re: Retrieving message attachments using ExOLEDB   
Glen,

Thanks for the reply.  I guess I thought I _was_ using CDOEX.  I've found 
the Exchange SDK docs to be very confusing in the way that all the various 
ways of accessing the Exchange server are jumbled together.  I'll have a look 
at these URL and see if that helps...

Thanks again,

Joe


"Glen Scales [MVP]" wrote:

> Your better of using CDOEX to process attachments, CDOEX still uses Exoledb 
> as the means of accessing the store but gives you some better interfaces for 
> manipulating messages. see 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_ibodypart_filename.asp 
> and also 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_extracting_embedded_messages.asp
> 
> Cheers
> Glen
> 
> "jwh20"  wrote in message 
> news:D8F49AD0-5CB1-45FA-80AC-F5ABBF035211@microsoft.com...
> > I'm working on a project to archive messages from a specific mailbox in
> > Exchange and store the information in a database.  I have something like:
> >
> > ' Open the connection to the Exchange message store using ExOLEDB
> > Set Conn = CreateObject("ADODB.Connection")
> > Conn.Provider = "ExOLEDB.DataSource"
> > surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user &
> > "/Inbox"
> > Conn.Open sUrl
> >
> > Dim Rs
> > Set Rs = CreateObject("ADODB.Recordset")
> >
> > ' SQL to return the desired fields from the Exchange server
> > Dim sql
> > sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"",
> > ""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"",
> > ""urn:schemas:httpmail:subject"", 
> > ""urn:schemas:httpmail:textdescription"",
> > ""urn:schemas:mailheader:message-id"",
> > ""urn:schemas:httpmail:attachmentfilename"" from"
> > sql = sql & " scope('shallow traversal of """ & sUrl & """')"
> > sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = False"
> >
> > Everything is as expected here EXCEPT the
> > urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty 
> > regardless
> > of whether the message has an attachment or not.
> >
> > Question: What is the proper method to get the attachment so that I can
> > store it away?
> >
> > Thanks... 
> 
> 
>
date: Mon, 19 Dec 2005 16:02:02 -0800   author:   jwh20

Re: Retrieving message attachments using ExOLEDB   
Glen,

I found an earlier posting by you in the 
microsoft.public.exchange.development  group and did the following based on 
that.  I do get the attachement saved to a file as expected.  But I really 
don't want it in a file.  I want to store it in a SQL database.  I tried 
using ReadText and/or Read to get the attachment into a variable in the 
script but that doesn't seem to work.  

I also bypass any rfc22 type attachments since they don't seem to work with 
the SaveToFile method.


	' Process any attachments
	If Rs("urn:schemas:httpmail:hasattachment") Then
		Set rec = CreateObject("ADODB.Record")
		Set msgobj = CreateObject("CDO.Message")

		rec.Open surl & "/" & Rs("DAV:displayname")
		msgobj.DataSource.OpenObject rec.Fields(-1).value, "_Stream"

		For Each objAttachment In msgobj.Attachments
			WScript.Echo " Attachment: " & objAttachment.filename & " (" & 
objAttachment.ContentMediaType & ")" & vbCrLf

			Set objAttachStream = objAttachment.GetDecodedContentStream
			If objAttachment.ContentMediaType <> "message/rfc822" Then
				objAttachStream.SaveToFile "D:\archive\temp\" & objAttachment.FileName
			End If
		Next

		Set msgobj = Nothing
		Set rec = Nothing
	End If

"jwh20" wrote:

> Glen,
> 
> Thanks for the reply.  I guess I thought I _was_ using CDOEX.  I've found 
> the Exchange SDK docs to be very confusing in the way that all the various 
> ways of accessing the Exchange server are jumbled together.  I'll have a look 
> at these URL and see if that helps...
> 
> Thanks again,
> 
> Joe
> 
> 
> "Glen Scales [MVP]" wrote:
> 
> > Your better of using CDOEX to process attachments, CDOEX still uses Exoledb 
> > as the means of accessing the store but gives you some better interfaces for 
> > manipulating messages. see 
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_ibodypart_filename.asp 
> > and also 
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_extracting_embedded_messages.asp
> > 
> > Cheers
> > Glen
> > 
> > "jwh20"  wrote in message 
> > news:D8F49AD0-5CB1-45FA-80AC-F5ABBF035211@microsoft.com...
> > > I'm working on a project to archive messages from a specific mailbox in
> > > Exchange and store the information in a database.  I have something like:
> > >
> > > ' Open the connection to the Exchange message store using ExOLEDB
> > > Set Conn = CreateObject("ADODB.Connection")
> > > Conn.Provider = "ExOLEDB.DataSource"
> > > surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user &
> > > "/Inbox"
> > > Conn.Open sUrl
> > >
> > > Dim Rs
> > > Set Rs = CreateObject("ADODB.Recordset")
> > >
> > > ' SQL to return the desired fields from the Exchange server
> > > Dim sql
> > > sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"",
> > > ""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"",
> > > ""urn:schemas:httpmail:subject"", 
> > > ""urn:schemas:httpmail:textdescription"",
> > > ""urn:schemas:mailheader:message-id"",
> > > ""urn:schemas:httpmail:attachmentfilename"" from"
> > > sql = sql & " scope('shallow traversal of """ & sUrl & """')"
> > > sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = False"
> > >
> > > Everything is as expected here EXCEPT the
> > > urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty 
> > > regardless
> > > of whether the message has an attachment or not.
> > >
> > > Question: What is the proper method to get the attachment so that I can
> > > store it away?
> > >
> > > Thanks... 
> > 
> > 
> >
date: Mon, 19 Dec 2005 17:02:02 -0800   author:   jwh20

Re: Retrieving message attachments using ExOLEDB   
You dont need to open the message from the record stream just open it 
directly using datasource.open

eg

Set msgobj = CreateObject("CDO.Message")
msgobj.DataSource.Open Rs("DAV:displayname"),,3

If the attachment has a contenttype of rfc822 then the attachment is an 
attached message weather you want to process any attachments that are on 
this attached message is up to you. I've put up some code up to do that at 
http://gsexdev.blogspot.com/2004/07/processing-attachments-in-embedded.html

As for writing to database I usually just write the MIME encoded text to a 
Text field in a database using Readtext I've had sucess with the following 
code
http://gsexdev.blogspot.com/2005/07/shared-mailbox-database-public-folder.html. 
The only thing to remember when you using this method is that you need to 
decode the MIME text when you want to make use of the file. If you get 
errors when you try this what are the exact errors you are getting.

Cheers
Glen



"jwh20"  wrote in message 
news:A3CA26C2-79BB-491E-9EB2-D4E421B6B1C0@microsoft.com...
> Glen,
>
> I found an earlier posting by you in the
> microsoft.public.exchange.development  group and did the following based 
> on
> that.  I do get the attachement saved to a file as expected.  But I really
> don't want it in a file.  I want to store it in a SQL database.  I tried
> using ReadText and/or Read to get the attachment into a variable in the
> script but that doesn't seem to work.
>
> I also bypass any rfc22 type attachments since they don't seem to work 
> with
> the SaveToFile method.
>
>
> ' Process any attachments
> If Rs("urn:schemas:httpmail:hasattachment") Then
> Set rec = CreateObject("ADODB.Record")
> Set msgobj = CreateObject("CDO.Message")
>
> rec.Open surl & "/" & Rs("DAV:displayname")
> msgobj.DataSource.OpenObject rec.Fields(-1).value, "_Stream"
>
> For Each objAttachment In msgobj.Attachments
> WScript.Echo " Attachment: " & objAttachment.filename & " (" &
> objAttachment.ContentMediaType & ")" & vbCrLf
>
> Set objAttachStream = objAttachment.GetDecodedContentStream
> If objAttachment.ContentMediaType <> "message/rfc822" Then
> objAttachStream.SaveToFile "D:\archive\temp\" & objAttachment.FileName
> End If
> Next
>
> Set msgobj = Nothing
> Set rec = Nothing
> End If
>
> "jwh20" wrote:
>
>> Glen,
>>
>> Thanks for the reply.  I guess I thought I _was_ using CDOEX.  I've found
>> the Exchange SDK docs to be very confusing in the way that all the 
>> various
>> ways of accessing the Exchange server are jumbled together.  I'll have a 
>> look
>> at these URL and see if that helps...
>>
>> Thanks again,
>>
>> Joe
>>
>>
>> "Glen Scales [MVP]" wrote:
>>
>> > Your better of using CDOEX to process attachments, CDOEX still uses 
>> > Exoledb
>> > as the means of accessing the store but gives you some better 
>> > interfaces for
>> > manipulating messages. see
>> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_ibodypart_filename.asp
>> > and also
>> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_extracting_embedded_messages.asp
>> >
>> > Cheers
>> > Glen
>> >
>> > "jwh20"  wrote in message
>> > news:D8F49AD0-5CB1-45FA-80AC-F5ABBF035211@microsoft.com...
>> > > I'm working on a project to archive messages from a specific mailbox 
>> > > in
>> > > Exchange and store the information in a database.  I have something 
>> > > like:
>> > >
>> > > ' Open the connection to the Exchange message store using ExOLEDB
>> > > Set Conn = CreateObject("ADODB.Connection")
>> > > Conn.Provider = "ExOLEDB.DataSource"
>> > > surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user 
>> > > &
>> > > "/Inbox"
>> > > Conn.Open sUrl
>> > >
>> > > Dim Rs
>> > > Set Rs = CreateObject("ADODB.Recordset")
>> > >
>> > > ' SQL to return the desired fields from the Exchange server
>> > > Dim sql
>> > > sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"",
>> > > ""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"",
>> > > ""urn:schemas:httpmail:subject"",
>> > > ""urn:schemas:httpmail:textdescription"",
>> > > ""urn:schemas:mailheader:message-id"",
>> > > ""urn:schemas:httpmail:attachmentfilename"" from"
>> > > sql = sql & " scope('shallow traversal of """ & sUrl & """')"
>> > > sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = 
>> > > False"
>> > >
>> > > Everything is as expected here EXCEPT the
>> > > urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty
>> > > regardless
>> > > of whether the message has an attachment or not.
>> > >
>> > > Question: What is the proper method to get the attachment so that I 
>> > > can
>> > > store it away?
>> > >
>> > > Thanks...
>> >
>> >
>> >
date: Tue, 20 Dec 2005 14:41:21 +1100   author:   Glen Scales [MVP]

Re: Retrieving message attachments using ExOLEDB   
Glen,

I was getting:

ADODB.Stream: Operation is not allowed in this context.

When attempting to use the ReadText or Read methods on the stream.  

But after looking at your blog examples I was able to get the whole thing 
working as desired.  Not sure why that was the case, I had a stream from the 
GetEncodedContentStream method so I think it should have worked.  Perhaps I 
was not doing it in the right sequence...  Anyway, thanks...

I appreciate your help on this.  Keep up the good work!!

Regards,

Joe

"Glen Scales [MVP]" wrote:

> You dont need to open the message from the record stream just open it 
> directly using datasource.open
> 
> eg
> 
> Set msgobj = CreateObject("CDO.Message")
> msgobj.DataSource.Open Rs("DAV:displayname"),,3
> 
> If the attachment has a contenttype of rfc822 then the attachment is an 
> attached message weather you want to process any attachments that are on 
> this attached message is up to you. I've put up some code up to do that at 
> http://gsexdev.blogspot.com/2004/07/processing-attachments-in-embedded.html
> 
> As for writing to database I usually just write the MIME encoded text to a 
> Text field in a database using Readtext I've had sucess with the following 
> code
> http://gsexdev.blogspot.com/2005/07/shared-mailbox-database-public-folder.html. 
> The only thing to remember when you using this method is that you need to 
> decode the MIME text when you want to make use of the file. If you get 
> errors when you try this what are the exact errors you are getting.
> 
> Cheers
> Glen
> 
> 
> 
> "jwh20"  wrote in message 
> news:A3CA26C2-79BB-491E-9EB2-D4E421B6B1C0@microsoft.com...
> > Glen,
> >
> > I found an earlier posting by you in the
> > microsoft.public.exchange.development  group and did the following based 
> > on
> > that.  I do get the attachement saved to a file as expected.  But I really
> > don't want it in a file.  I want to store it in a SQL database.  I tried
> > using ReadText and/or Read to get the attachment into a variable in the
> > script but that doesn't seem to work.
> >
> > I also bypass any rfc22 type attachments since they don't seem to work 
> > with
> > the SaveToFile method.
> >
> >
> > ' Process any attachments
> > If Rs("urn:schemas:httpmail:hasattachment") Then
> > Set rec = CreateObject("ADODB.Record")
> > Set msgobj = CreateObject("CDO.Message")
> >
> > rec.Open surl & "/" & Rs("DAV:displayname")
> > msgobj.DataSource.OpenObject rec.Fields(-1).value, "_Stream"
> >
> > For Each objAttachment In msgobj.Attachments
> > WScript.Echo " Attachment: " & objAttachment.filename & " (" &
> > objAttachment.ContentMediaType & ")" & vbCrLf
> >
> > Set objAttachStream = objAttachment.GetDecodedContentStream
> > If objAttachment.ContentMediaType <> "message/rfc822" Then
> > objAttachStream.SaveToFile "D:\archive\temp\" & objAttachment.FileName
> > End If
> > Next
> >
> > Set msgobj = Nothing
> > Set rec = Nothing
> > End If
> >
> > "jwh20" wrote:
> >
> >> Glen,
> >>
> >> Thanks for the reply.  I guess I thought I _was_ using CDOEX.  I've found
> >> the Exchange SDK docs to be very confusing in the way that all the 
> >> various
> >> ways of accessing the Exchange server are jumbled together.  I'll have a 
> >> look
> >> at these URL and see if that helps...
> >>
> >> Thanks again,
> >>
> >> Joe
> >>
> >>
> >> "Glen Scales [MVP]" wrote:
> >>
> >> > Your better of using CDOEX to process attachments, CDOEX still uses 
> >> > Exoledb
> >> > as the means of accessing the store but gives you some better 
> >> > interfaces for
> >> > manipulating messages. see
> >> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_ibodypart_filename.asp
> >> > and also
> >> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_extracting_embedded_messages.asp
> >> >
> >> > Cheers
> >> > Glen
> >> >
> >> > "jwh20"  wrote in message
> >> > news:D8F49AD0-5CB1-45FA-80AC-F5ABBF035211@microsoft.com...
> >> > > I'm working on a project to archive messages from a specific mailbox 
> >> > > in
> >> > > Exchange and store the information in a database.  I have something 
> >> > > like:
> >> > >
> >> > > ' Open the connection to the Exchange message store using ExOLEDB
> >> > > Set Conn = CreateObject("ADODB.Connection")
> >> > > Conn.Provider = "ExOLEDB.DataSource"
> >> > > surl = "file://./backofficestorage/" & serverdomain & "/MBX/" & user 
> >> > > &
> >> > > "/Inbox"
> >> > > Conn.Open sUrl
> >> > >
> >> > > Dim Rs
> >> > > Set Rs = CreateObject("ADODB.Recordset")
> >> > >
> >> > > ' SQL to return the desired fields from the Exchange server
> >> > > Dim sql
> >> > > sql = "select ""DAV:displayname"", ""urn:schemas:httpmail:to"",
> >> > > ""urn:schemas:httpmail:from"", ""urn:schemas:httpmail:date"",
> >> > > ""urn:schemas:httpmail:subject"",
> >> > > ""urn:schemas:httpmail:textdescription"",
> >> > > ""urn:schemas:mailheader:message-id"",
> >> > > ""urn:schemas:httpmail:attachmentfilename"" from"
> >> > > sql = sql & " scope('shallow traversal of """ & sUrl & """')"
> >> > > sql = sql & " where ""DAV:ishidden"" = False and ""DAV:isfolder"" = 
> >> > > False"
> >> > >
> >> > > Everything is as expected here EXCEPT the
> >> > > urn:schemas:httpmail:attachmentfilename item.  It's ALWAYS empty
> >> > > regardless
> >> > > of whether the message has an attachment or not.
> >> > >
> >> > > Question: What is the proper method to get the attachment so that I 
> >> > > can
> >> > > store it away?
> >> > >
> >> > > Thanks...
> >> >
> >> >
> >> > 
> 
> 
>
date: Tue, 20 Dec 2005 03:11:02 -0800   author:   jwh20

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us