| Author |
Message |
Andrew Inwards
Guest
|
Posted:
Wed Nov 24, 2004 1:00 am Post subject:
Delete Message in Save Event Sink |
|
|
Ive written an Exchange 2003 .Net Event Sink to process email messages and I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
| Back to top |
|
 |
Glen Scales [MVP]
Guest
|
Posted:
Wed Nov 24, 2004 6:56 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
| Quote: | Ive written an Exchange 2003 .Net Event Sink to process email messages and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Andrew Inwards
Guest
|
Posted:
Wed Nov 24, 2004 4:32 pm Post subject:
Re: Delete Message in Save Event Sink |
|
|
This is the code that Im trying to get to compile. The function sits within
the Async Save Event on the Message Store.
public void DeleteMessage(string bstrURLItem, CDO.Message iMessage)
{
ADODB.Record rMessage = new ADODB.Record();
Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
iMessage.DataSource.ActiveConnection,ConnectModeEnum.adModeReadWrite);
rMessage.DeleteRecord(bstrURLItem,false);
rMessage.Close();
Conn.Close();
}
For some reason the function Conn.Open(bstrURLItem) is complaining that -No
overload for method 'Open' takes '1' arguments.
The same error occurs on the rMessage.Open call
My imports are as follows:
using System;
using System.IO;
using System.Text;
using System.Xml;
using CDO;
using ADODB;
using System.Reflection;
using Exoledb = Interop.Exoledb;
using ExevtsnkLib = Interop.Exevtsnk;
using System.EnterpriseServices;
using Microsoft.Win32;
Any thoughts?
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
| Quote: | Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to
delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email messages
and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Andrew Inwards
Guest
|
Posted:
Wed Nov 24, 2004 8:38 pm Post subject:
Re: Delete Message in Save Event Sink |
|
|
OK Ive made progress- my program complies and my DeleteMessage function is
getting called. However the message doesnt get deleted and no errors are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
| Quote: | Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to
delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email messages
and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Glen Scales [MVP]
Guest
|
Posted:
Thu Nov 25, 2004 7:21 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
The code looks okay, does that account that you have the event sink running
under have rights within the mailbox where the sink is running to delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules running
on the mailbox where this sink is running (this has caused problems before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete function
does this work
Do you have multiple sinks or multiple copies of the sink registered on that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
| Quote: | OK Ive made progress- my program complies and my DeleteMessage function is
getting called. However the message doesnt get deleted and no errors are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to
delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email messages
and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Andrew
Guest
|
Posted:
Fri Nov 26, 2004 4:58 pm Post subject:
Re: Delete Message in Save Event Sink |
|
|
What Ive discovered is that if I run the event sink under the account
of the mailbox that I want to delete from then sometimes it deletes
the message and other times it doesnt. When it fails it generates the
following com+ error in the event log-
A condition has occurred that indicates this COM+ application is in an
unstable state or is not functioning correctly. Assertion Failure:
!m_fActivated
Server Application ID: {38372A75-6414-4C4D-9754-A87404A8058D}
Server Application Instance ID:
{4D37407F-10E4-41AE-B4BB-7E337A5FA62B}
Server Application Name: FOIEventSink
The serious nature of this error has caused the process to terminate.
COM+ Services Internals Information:
File: d:\srv03rtm\com\complus\src\comsvcs\jit\jit.cpp, Line: 92
Comsvcs.dll file version: ENU 2001.12.4720.0 shp
I only have one sink registered. Any Thoughts? What COM + settings
should I apply to the event sink?
Thanks for you help so far.
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
| Quote: | The code looks okay, does that account that you have the event sink running
under have rights within the mailbox where the sink is running to delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules running
on the mailbox where this sink is running (this has caused problems before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete function
does this work
Do you have multiple sinks or multiple copies of the sink registered on that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage function is
getting called. However the message doesnt get deleted and no errors are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to
delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email messages
and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Andrew
Guest
|
Posted:
Sat Nov 27, 2004 12:11 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
Ive discovered that I can delete the message if I just call my
DeleteMessage Method. However I need to query some properties of the
message before hand. The thing is that if I open teh message to query
it then my code to delete it doesnt cause the mesage to be deleted - I
guess because there is still a reference, but I think that Im
releasing the reference. Here is the code:
iMessage.DataSource.Open(bstrURLItem,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
OpenLogFile();
GetRegistrySettings();
WriteToLog("Processing Message - " + bstrURLItem);
WriteToLog("Log File Path - " + strLogPath);
WriteToLog("Logging - " + strLogging);
WriteToLog("Subject - " + strSubject);
WriteToLog("Email Address - " + strEmailAddress);
if (string.Compare(ParseEmail(iMessage.From),strEmailAddress)
==0)
{
if (string.Compare(iMessage.Subject,strSubject,false)==0)
{
WriteToLog("Subject Matched");
if (iMessage.Attachments.Count == 1)
{
WriteToLog("Attachment Found");
iMessage.DataSource.ActiveConnection.Close();
iMessage = null;
DeleteMessage(bstrURLItem);
Any thoughts?
Thanks
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
| Quote: | The code looks okay, does that account that you have the event sink running
under have rights within the mailbox where the sink is running to delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules running
on the mailbox where this sink is running (this has caused problems before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete function
does this work
Do you have multiple sinks or multiple copies of the sink registered on that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage function is
getting called. However the message doesnt get deleted and no errors are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async event or
Synchronous event sink . In a Async event sink just use Exoled/ADO to
delete
it eg open a record based on the bstrURLItem (make sure you open it as
read/write) and then call deleterecord. In a Synchronous you can call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email messages
and
I
cant figure out how to delete the message once I'm finished with it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Glen Scales [MVP]
Guest
|
Posted:
Mon Nov 29, 2004 4:13 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
You might want to try forcing garbage collection (before you call the delete
method) have a look at
http://www.developer.com/net/csharp/article.php/3343191 and
http://www.c-sharpcorner.com/Code/2002/Aug/GCinNet.asp
Cheers
Glen
"Andrew" <inwards@hotmail.com> wrote in message
news:af7e9049.0411261011.6b6b7364@posting.google.com...
| Quote: | Ive discovered that I can delete the message if I just call my
DeleteMessage Method. However I need to query some properties of the
message before hand. The thing is that if I open teh message to query
it then my code to delete it doesnt cause the mesage to be deleted - I
guess because there is still a reference, but I think that Im
releasing the reference. Here is the code:
iMessage.DataSource.Open(bstrURLItem,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
OpenLogFile();
GetRegistrySettings();
WriteToLog("Processing Message - " + bstrURLItem);
WriteToLog("Log File Path - " + strLogPath);
WriteToLog("Logging - " + strLogging);
WriteToLog("Subject - " + strSubject);
WriteToLog("Email Address - " + strEmailAddress);
if (string.Compare(ParseEmail(iMessage.From),strEmailAddress)
==0)
{
if (string.Compare(iMessage.Subject,strSubject,false)==0)
{
WriteToLog("Subject Matched");
if (iMessage.Attachments.Count == 1)
{
WriteToLog("Attachment Found");
iMessage.DataSource.ActiveConnection.Close();
iMessage = null;
DeleteMessage(bstrURLItem);
Any thoughts?
Thanks
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
The code looks okay, does that account that you have the event sink
running
under have rights within the mailbox where the sink is running to delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules
running
on the mailbox where this sink is running (this has caused problems
before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete function
does this work
Do you have multiple sinks or multiple copies of the sink registered on
that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage
function is
getting called. However the message doesnt get deleted and no errors
are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set
the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which
will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async
event or
Synchronous event sink . In a Async event sink just use Exoled/ADO
to
delete
it eg open a record based on the bstrURLItem (make sure you open it
as
read/write) and then call deleterecord. In a Synchronous you can
call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email
messages
and
I
cant figure out how to delete the message once I'm finished with
it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Andrew Inwards
Guest
|
Posted:
Mon Nov 29, 2004 3:22 pm Post subject:
Re: Delete Message in Save Event Sink |
|
|
Still no joy - If I call iMessage.DataSource.ActiveConnection.Close I get
the error - Object reference not set to an instance of an object and if I
just set the iMessage object to null then I still get the COM + error
A condition has occurred that indicates this COM+ application is in an
unstable state or is not functioning correctly. Assertion Failure:
!m_fActivated
when I try and delete the message. Am I missing something here about
releasing the memery/refernce for the iMessage object?
Thanks for you help
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23A67JeZ1EHA.1204@TK2MSFTNGP10.phx.gbl...
| Quote: | You might want to try forcing garbage collection (before you call the
delete
method) have a look at
http://www.developer.com/net/csharp/article.php/3343191 and
http://www.c-sharpcorner.com/Code/2002/Aug/GCinNet.asp
Cheers
Glen
"Andrew" <inwards@hotmail.com> wrote in message
news:af7e9049.0411261011.6b6b7364@posting.google.com...
Ive discovered that I can delete the message if I just call my
DeleteMessage Method. However I need to query some properties of the
message before hand. The thing is that if I open teh message to query
it then my code to delete it doesnt cause the mesage to be deleted - I
guess because there is still a reference, but I think that Im
releasing the reference. Here is the code:
iMessage.DataSource.Open(bstrURLItem,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
OpenLogFile();
GetRegistrySettings();
WriteToLog("Processing Message - " + bstrURLItem);
WriteToLog("Log File Path - " + strLogPath);
WriteToLog("Logging - " + strLogging);
WriteToLog("Subject - " + strSubject);
WriteToLog("Email Address - " + strEmailAddress);
if (string.Compare(ParseEmail(iMessage.From),strEmailAddress)
==0)
{
if (string.Compare(iMessage.Subject,strSubject,false)==0)
{
WriteToLog("Subject Matched");
if (iMessage.Attachments.Count == 1)
{
WriteToLog("Attachment Found");
iMessage.DataSource.ActiveConnection.Close();
iMessage = null;
DeleteMessage(bstrURLItem);
Any thoughts?
Thanks
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
The code looks okay, does that account that you have the event sink
running
under have rights within the mailbox where the sink is running to
delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules
running
on the mailbox where this sink is running (this has caused problems
before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete
function
does this work
Do you have multiple sinks or multiple copies of the sink registered
on
that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage
function is
getting called. However the message doesnt get deleted and no errors
are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set
the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which
will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async
event or
Synchronous event sink . In a Async event sink just use Exoled/ADO
to
delete
it eg open a record based on the bstrURLItem (make sure you open
it
as
read/write) and then call deleterecord. In a Synchronous you can
call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email
messages
and
I
cant figure out how to delete the message once I'm finished with
it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
Sven Carstensen
Guest
|
Posted:
Sun Dec 05, 2004 6:20 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
Hi Andrew,
call ReleaseComObject on all the COM interop wrapper objects.
Otherwise the GC will call Release quite late on some COM objects so
their cleanup code might run too late.
IIRC it is part of System.Runtime.Interop.Marshal. Call
ReleaseComObject in the reverse order you created your COM objects.
HTH,
SvenC
"Andrew Inwards" <andrew@nospam.com> wrote in message news:<eXddCUf1EHA.1292@TK2MSFTNGP10.phx.gbl>...
| Quote: | Still no joy - If I call iMessage.DataSource.ActiveConnection.Close I get
the error - Object reference not set to an instance of an object and if I
just set the iMessage object to null then I still get the COM + error
A condition has occurred that indicates this COM+ application is in an
unstable state or is not functioning correctly. Assertion Failure:
!m_fActivated
when I try and delete the message. Am I missing something here about
releasing the memery/refernce for the iMessage object?
Thanks for you help
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23A67JeZ1EHA.1204@TK2MSFTNGP10.phx.gbl...
You might want to try forcing garbage collection (before you call the
delete
method) have a look at
http://www.developer.com/net/csharp/article.php/3343191 and
http://www.c-sharpcorner.com/Code/2002/Aug/GCinNet.asp
Cheers
Glen
"Andrew" <inwards@hotmail.com> wrote in message
news:af7e9049.0411261011.6b6b7364@posting.google.com...
Ive discovered that I can delete the message if I just call my
DeleteMessage Method. However I need to query some properties of the
message before hand. The thing is that if I open teh message to query
it then my code to delete it doesnt cause the mesage to be deleted - I
guess because there is still a reference, but I think that Im
releasing the reference. Here is the code:
iMessage.DataSource.Open(bstrURLItem,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
OpenLogFile();
GetRegistrySettings();
WriteToLog("Processing Message - " + bstrURLItem);
WriteToLog("Log File Path - " + strLogPath);
WriteToLog("Logging - " + strLogging);
WriteToLog("Subject - " + strSubject);
WriteToLog("Email Address - " + strEmailAddress);
if (string.Compare(ParseEmail(iMessage.From),strEmailAddress)
==0)
{
if (string.Compare(iMessage.Subject,strSubject,false)==0)
{
WriteToLog("Subject Matched");
if (iMessage.Attachments.Count == 1)
{
WriteToLog("Attachment Found");
iMessage.DataSource.ActiveConnection.Close();
iMessage = null;
DeleteMessage(bstrURLItem);
Any thoughts?
Thanks
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
The code looks okay, does that account that you have the event sink
running
under have rights within the mailbox where the sink is running to
delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules
running
on the mailbox where this sink is running (this has caused problems
before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete
function
does this work
Do you have multiple sinks or multiple copies of the sink registered
on
that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage
function is
getting called. However the message doesnt get deleted and no errors
are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set
the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which
will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async
event or
Synchronous event sink . In a Async event sink just use Exoled/ADO
to
delete
it eg open a record based on the bstrURLItem (make sure you open
it
as
read/write) and then call deleterecord. In a Synchronous you can
call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email
messages
and
I
cant figure out how to delete the message once I'm finished with
it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
David A. Coursey
Guest
|
Posted:
Fri Jan 21, 2005 2:57 am Post subject:
Re: Delete Message in Save Event Sink |
|
|
Andrew, did you ever get this to work? I'm doing exactly the same thing and
having trouble.
dave
"Sven Carstensen" wrote:
| Quote: | Hi Andrew,
call ReleaseComObject on all the COM interop wrapper objects.
Otherwise the GC will call Release quite late on some COM objects so
their cleanup code might run too late.
IIRC it is part of System.Runtime.Interop.Marshal. Call
ReleaseComObject in the reverse order you created your COM objects.
HTH,
SvenC
"Andrew Inwards" <andrew@nospam.com> wrote in message news:<eXddCUf1EHA.1292@TK2MSFTNGP10.phx.gbl>...
Still no joy - If I call iMessage.DataSource.ActiveConnection.Close I get
the error - Object reference not set to an instance of an object and if I
just set the iMessage object to null then I still get the COM + error
A condition has occurred that indicates this COM+ application is in an
unstable state or is not functioning correctly. Assertion Failure:
!m_fActivated
when I try and delete the message. Am I missing something here about
releasing the memery/refernce for the iMessage object?
Thanks for you help
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23A67JeZ1EHA.1204@TK2MSFTNGP10.phx.gbl...
You might want to try forcing garbage collection (before you call the
delete
method) have a look at
http://www.developer.com/net/csharp/article.php/3343191 and
http://www.c-sharpcorner.com/Code/2002/Aug/GCinNet.asp
Cheers
Glen
"Andrew" <inwards@hotmail.com> wrote in message
news:af7e9049.0411261011.6b6b7364@posting.google.com...
Ive discovered that I can delete the message if I just call my
DeleteMessage Method. However I need to query some properties of the
message before hand. The thing is that if I open teh message to query
it then my code to delete it doesnt cause the mesage to be deleted - I
guess because there is still a reference, but I think that Im
releasing the reference. Here is the code:
iMessage.DataSource.Open(bstrURLItem,null,
ADODB.ConnectModeEnum.adModeRead,
ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
ADODB.RecordOpenOptionsEnum.adOpenSource,"","");
OpenLogFile();
GetRegistrySettings();
WriteToLog("Processing Message - " + bstrURLItem);
WriteToLog("Log File Path - " + strLogPath);
WriteToLog("Logging - " + strLogging);
WriteToLog("Subject - " + strSubject);
WriteToLog("Email Address - " + strEmailAddress);
if (string.Compare(ParseEmail(iMessage.From),strEmailAddress)
==0)
{
if (string.Compare(iMessage.Subject,strSubject,false)==0)
{
WriteToLog("Subject Matched");
if (iMessage.Attachments.Count == 1)
{
WriteToLog("Attachment Found");
iMessage.DataSource.ActiveConnection.Close();
iMessage = null;
DeleteMessage(bstrURLItem);
Any thoughts?
Thanks
Andrew
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:<ujVZT0o0EHA.1392@tk2msftngp13.phx.gbl>...
The code looks okay, does that account that you have the event sink
running
under have rights within the mailbox where the sink is running to
delete
email.
With a Async sink the message is actually going to be delivered to the
mailbox first before the sink is called do you have any inbox rules
running
on the mailbox where this sink is running (this has caused problems
before
with me)
Are other parts of your code creating a lock on the message (are you
cleaning up properly).If you create a sink with just the delete
function
does this work
Do you have multiple sinks or multiple copies of the sink registered
on
that
folder.
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uWU5PNj0EHA.3596@TK2MSFTNGP12.phx.gbl...
OK Ive made progress- my program complies and my DeleteMessage
function is
getting called. However the message doesnt get deleted and no errors
are
raised.
public void DeleteMessage(string bstrURLItem)
{
WriteToLog("Attempting to delete Message");
ADODB.Record rMessage = new ADODB.Record();
try
{
ADODB.Connection oCn = new ADODB.Connection();
oCn.Provider = "exoledb.datasource";
oCn.Open(bstrURLItem, "", "", -1);
if(oCn.State == 1)
{
WriteToLog("Good Connection");
}
else
{
WriteToLog("Bad Connection");
}
//Conn.Open(bstrURLItem);
rMessage.Open (bstrURLItem,
oCn,ConnectModeEnum.adModeReadWrite,RecordCreateOptionsEnum.adFailIfNotExist
s,RecordOpenOptionsEnum.adOpenSource,"","");
rMessage.DeleteRecord(bstrURLItem,false);
WriteToLog("Message Deleted");
//Conn.Close();
}
catch (Exception ex)
{
WriteToLog("Failed to delete message - " + ex.Message);
}
finally
{
rMessage.Close();
}
}
"Glen Scales [MVP]" <gscales@outlookexchange.com> wrote in message
news:%23oghMCc0EHA.3820@TK2MSFTNGP11.phx.gbl...
Are you talking about a SMTP event sink or a store event sink ?
In a SMTP event sink you can't delete the message but you can set
the
message status envelope field to 2
http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus which
will
abort
delivery of the message.
In a store event sink it depends wether you are writing a Async
event or
Synchronous event sink . In a Async event sink just use Exoled/ADO
to
delete
it eg open a record based on the bstrURLItem (make sure you open
it
as
read/write) and then call deleterecord. In a Synchronous you can
call
the
abort method which should abort delivery of the message see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_iexstoreeventinfo_abort.asp
Cheers
Glen
"Andrew Inwards" <andrew@nospam.com> wrote in message
news:uSmWA7Y0EHA.1932@TK2MSFTNGP09.phx.gbl...
Ive written an Exchange 2003 .Net Event Sink to process email
messages
and
I
cant figure out how to delete the message once I'm finished with
it.
Please can some helpful person point me in the right direction.
Thanks
Andrew
|
|
|
| Back to top |
|
 |
|
|
|
|