473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SaveToFile within Exchange Store Event

I have an async OnStore event written in c# and registered in exchange 2003.
Everything seems to be working fine other than the SaveToFile().
If there is an error in the iMessage.DataSource.Open ( ie. the message has
moved ) the expected exception is raised and caught.
However when the strm.SaveToFile() is executed the process just seems to
die - no output file is generated , no exceptions raised , no system log
entries , no more log() entries are written - nothing.
If I comment this line out , the method runs to completion as it should.

The log() method writes to a log in the same target directory as the
SaveToFile so this is not a permissions problem on the destination file.

any insights here would be appreciated

gerry

void IExStoreAsyncEvents.OnSave( IExStoreEventInfo info , string url , int
flags )
{
pid=System.DateTime.Now.Ticks;
IExStoreDispEventInfo dinfo = (IExStoreDispEventInfo)info;
log("OnSave",String.Format("url:{0}\n\tflags:0x{1: x4}\n\tsource URL :
{2}",url,flags,dinfo.SourceURL));

// if ( ( flags & 0x08 ) != 0x00 ) return;

// sleep here to let system filters/rules etc take effect
// if message is moved elsewhere - Open will fail
log("OnSave","Sleep(1)");
System.Threading.Thread.Sleep(4000);
log("OnSave","1");

try
{
log("OnSave","iMessage=new CDO.Message()");
CDO.Message iMessage=new CDO.MessageClass();
log("OnSave","iMessage.DataSource.Open");
iMessage.DataSource.Open(url,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
try
{
String dstFile=String.Format("{0}\\m{1}.eml",appRoot,pid) ;
log("OnSave",dstFile);
log("OnSave","strm = iMessage.GetStream()");
ADODB.Stream strm = iMessage.GetStream();
log("OnSave","strm.SaveToFile");

strm.SaveToFile(dstFile,ADODB.SaveOptionsEnum.adSa veCreateOverWrite);
log("OnSave","saved");
strm.Close();
}
catch (Exception e)
{
log("Exc1",e.ToString());
}
}
catch (Exception e)
{
log("Exc2",e.ToString());
}
log("OnSave","Done");
}
Nov 16 '05 #1
4 3379
Hello Gerry,

Based on my understanding, the problem is: You are writing contents of one
message to a disk file in IExStoreAsyncEvents.OnSave function. However,
this stream.SaveToFile function doesn't write anything. Right?

Generally speaking, to save a serialized message from a Message object into
a Microsoft? ActiveX? Data Objects (ADO) Stream object, perform the
following steps:

1) Retrieve the IDataSource interface on the Message object.
2) Create or otherwise obtain a _Stream object reference on an ADO Stream
object.
3) Using the IDataSource interface on the Message object, call the
SaveToObject method, passing the _Stream object reference as the first
argument, and the string "_Stream" as the second

The sample VB code likes:
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Sub SaveMessageToFile(iMsg As CDO.Message, Filepath As String)
Dim Stm As New Stream
Stm.Open
Stm.Type = adTypeText
Stm.Charset = "US-ASCII"

Dim iDsrc As IDataSource
Set iDsrc = iMsg
iDsrc.SaveToObject Stm, "_Stream"

Stm.SaveToFile Filepath, adSaveCreateOverWrite

End Sub

For details, please refer to "Saving Messages into ADO Stream Objects"
topic in MSDN. Please search the topic and select "search in titles only"
to get that.

Also, you can refer to
http://msdn.microsoft.com/library/en...atasource_inte
rface.asp?frame=true for some demo code.

In Internet, we can also find a sample at
http://www.codeproject.com/csharp/Cs...SinksHooks.asp. However, it
is somewhat different since the author uses FileStream to save some content
to a file.

Please test the above and let me know whether it works. If there is any
questions, please feel free to let me know.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #2
Hi ,
thanks for the reply.

I did get this all staightened out - it turned out to be a simple fix
completely unrelated to my code which now works as stated without
modification.

since an exchange async store event handler has to be a com+ package, all
referenced .NET dlls have to be strongly named.
so i manually created & signed interop dll's for adodb.dll , exoledb.dll and
cdoex.dll.
what i didn't notice was that the required interop dll for adodb.dll is
already included with the .net installation.
using the distributed adodb interop dll instead of the one I created solved
the problem.
obviously ms has done some 'magic' in the generation of the adodb interop
dll to resolve some problem with standard interop dll generation.

gerry

"Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com> wrote in message
news:IE**************@cpmsftngxa06.phx.gbl...
Hello Gerry,

Based on my understanding, the problem is: You are writing contents of one
message to a disk file in IExStoreAsyncEvents.OnSave function. However,
this stream.SaveToFile function doesn't write anything. Right?

Generally speaking, to save a serialized message from a Message object into a Microsoft? ActiveX? Data Objects (ADO) Stream object, perform the
following steps:

1) Retrieve the IDataSource interface on the Message object.
2) Create or otherwise obtain a _Stream object reference on an ADO Stream
object.
3) Using the IDataSource interface on the Message object, call the
SaveToObject method, passing the _Stream object reference as the first
argument, and the string "_Stream" as the second

The sample VB code likes:
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Sub SaveMessageToFile(iMsg As CDO.Message, Filepath As String)
Dim Stm As New Stream
Stm.Open
Stm.Type = adTypeText
Stm.Charset = "US-ASCII"

Dim iDsrc As IDataSource
Set iDsrc = iMsg
iDsrc.SaveToObject Stm, "_Stream"

Stm.SaveToFile Filepath, adSaveCreateOverWrite

End Sub

For details, please refer to "Saving Messages into ADO Stream Objects"
topic in MSDN. Please search the topic and select "search in titles only"
to get that.

Also, you can refer to
http://msdn.microsoft.com/library/en...atasource_inte rface.asp?frame=true for some demo code.

In Internet, we can also find a sample at
http://www.codeproject.com/csharp/Cs...SinksHooks.asp. However, it is somewhat different since the author uses FileStream to save some content to a file.

Please test the above and let me know whether it works. If there is any
questions, please feel free to let me know.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #3
Hello Gerry,

Sorry that my suggestion didn't help you resolve the problem. However, I am
glad to know that you have figured it out by yourself. Thanks very much
for sharing your experience in the community and I believe it could benefit
other developers much.

Thanks again for participating the community.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #4
Please refer to MSDN:

' Reference to Microsoft CDO for Windows 2000 Library
http://msdn.microsoft.com/library/en...ogtasks_loadin
g_messages_from_within_ado_stream_objects.asp?fram e=true

Also, the code that Gerry provided also works. You can try it on your side.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mick Kehoe | last post by:
Hi All We are running SQL Server & Outlook with an exchange server. We are looking for a way to import the address book & email details into a database table. We have managed to do this with...
1
by: Patrick | last post by:
I'm trying to create a link from Access 2003 to an Exchange 2000 Public Folder called "WMContacts" I choose File => Get External Data=> Link Tables. I choose Exchange() and the wizard give me the...
3
by: Chad Myers | last post by:
I'm looking for an app that would allow me to download mails from various POP3 accounts and put them into my Exchange inbox on the server side (rather than having to have outlook open to do it...
0
by: gerry | last post by:
I have an async OnStore event written in c# and registered in exchange 2003. Everything seems to be working fine other than the SaveToFile(). If there is an error in the iMessage.DataSource.Open (...
1
by: Coder | last post by:
Hello, Is it possible to have an application sitting on the exchange server, and be able to read incoming emails? - Thanks.
0
by: JimDuggan | last post by:
I've written an event sink for Exchange 2000 in managed code, but have found problems now I've come to test it. My Exchange box needs upgrading to SP3 so I can install the Exchange SDK tools...
0
by: Jayme | last post by:
My company would like to implement an online calendar that integrates with our current website that would allow our clients to view upcoming workshops and events. These "appointments" are...
0
by: Mostro | last post by:
I have had an OMA problem for a month now, and cannot figure it out. A while back, can't rememeber a specific time, I was able to browse to my OMA at the local host using http://127.0.0.1/oma - it...
1
by: Robbert van Geldrop | last post by:
Hello, I have a problem restoring Exchange 2000 files. Our software has an interface to ESEBCLI2.dll for online backup and restore features. Everything works fine with Exchange 2003 and also...
4
by: Tarren | last post by:
Hi, All: I am tasked with the following. I need to write a service to monitor an Exchange mailbox and take action when an email is received, put it in a db, etc. I do not need to send emails...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.