473,657 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Managed Event Sink -- how to use CDO to get Subject and Message Body

I have written an event sink in C# that hooks into our Exchange Server
2000 store.

The sink fires and the various LOG files are created, but for some
reason I cannot seem to read-in the e-mail Subject or Message Body for
the e-mail that triggers the Event Sink to run.

What am I doing wrong?

Thank you,

Tom

=============== ===============
using System;
using System.Runtime. InteropServices ;
using System.Xml;
using CDO;
using ADODB;
using System.IO;
using System.Text;
using System.Enterpri seServices;

namespace MyEventSink
{
/// <summary>
/// Summary description for Class1.
/// </summary>
[Guid("16369924-5F32-4E26-AE89-8308B5C162E2")]

public class ExchEventSink: ServicedCompone nt , IExStoreAsyncEv ents
{
//public string ClassID = "F92EFC3A-FDD8-4225-B005-13FD3D5D54D1";
//public string InterfaceId =
"704A413F-F8FE-476B-9206-69AB6300D752";
//public string EventsId = "DCC71BD5-6627-4FBF-BB5A-DB8FEA1EB177";

public string ClassID = "cf63289d-18d1-43af-ba90-9e41cac93ee6";
public string InterfaceId = "323733b0-3c0d-47d4-86fa-fd67d651cf81";
public string EventsId = "3721271c-65f0-441a-91d6-6a86d1c75846";
public ExchEventSink()
{
}

#region IExStoreAsyncEv ents Members

public void OnSave(IExStore EventInfo pEventInfo, string bstrURLItem,
int lFlags)
{
try
{
if(System.Conve rt.ToBoolean(lF lags))
{
Process_mail(pE ventInfo, bstrURLItem);

FileStream fs = new
FileStream(@"c: \temp\ProofThat OnSaveIsWorking .log",FileMode. OpenOrCreate);
fs.Write(Encodi ng.ASCII.GetByt es(bstrURLItem) ,0,bstrURLItem. Length);
fs.Close();
}
}
catch (Exception ex)
{
throw (ex);
}
}

public void OnDelete(IExSto reEventInfo pEventInfo, string
bstrURLItem, int lFlags)
{
try
{

}
catch(Exception ex)
{
throw (ex);
}
}
#endregion
public void Process_mail(IE xStoreEventInfo pEventInfo, string
bstrURLItem)
{
try
{
FileStream fs = new
FileStream(@"c: \temp\MyEventSi nk.log",FileMod e.OpenOrCreate) ;
fs.Write(Encodi ng.ASCII.GetByt es(bstrURLItem) ,0,bstrURLItem. Length);
fs.Close();
}
catch(System.Ru ntime.InteropSe rvices.COMExcep tion ee)
{
throw(ee);
}
catch(Exception tom)
{
throw (tom);
}

try
{
CDO.Message iMessage=new CDO.MessageClas s();
ADODB.Stream stm;
CDO.IBodyPart iPrt;
int i;
int aNum;
string eName;
string fName;
string sFrom;
string sDate;
string sBody;
string sSubject;

iMessage.DataSo urce.Open(bstrU RLItem,null,ADO DB.ConnectModeE num.adModeRead, ADODB.RecordCre ateOptionsEnum. adFailIfNotExis ts,ADODB.Record OpenOptionsEnum .adOpenSource," ","");

//IExStoreDispEve ntInfo
newEventInfo=(I ExStoreDispEven tInfo)pEventInf o;
//ADODB.Record record=(ADODB.R ecord)newEventI nfo.EventRecord ;
sSubject = iMessage.Subjec t;
sBody = iMessage.TextBo dy;
sFrom = iMessage.From;
sDate = iMessage.Receiv edTime.ToString ();
aNum = iMessage.Attach ments.Count;

FileStream fsb = new
FileStream(@"c: \temp\NEWEST_SU BJECT_BODY_MyEv entSink.log",Fi leMode.OpenOrCr eate);
fsb.Write(Encod ing.ASCII.GetBy tes(sSubject + "::" +
sBody),0,sSubje ct.Length + "::".Length + sBody.Length);
fsb.Close();
for(i=1;i<=aNum ;i++)
{
fName = iMessage.Attach ments[i].FileName;
eName = fName.Substring (fName.Length-3,3).ToUpper();
if(eName == "TXT")
{
iPrt = iMessage.Attach ments[i];
iPrt.ContentMed iaType = "text/plain";
iPrt.Charset = "windows-1250";
stm = iPrt.GetDecoded ContentStream() ;
iPrt =null;
}
}
}
catch (Exception ex)
{
FileStream fs = new
FileStream(@"c: \temp\MyEventSi nkERRORERROR.lo g",FileMode.Ope nOrCreate);
fs.Write(Encodi ng.ASCII.GetByt es(ex.Message + ":::" +
ex.StackTrace), 0,ex.Message.Le ngth + ":::".Lengt h +
ex.StackTrace.L ength);
fs.Close();

throw (ex);
}
}
}
}
Nov 16 '05 #1
0 3625

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

Similar topics

1
1941
by: Bob Whiton | last post by:
I have an unmanaged class which has a member variable: gcroot<DataTable*> myDataTable; I would like to sink the RowDeleting event in my UNmanaged class. However, I can't declare an event handler in the unmanaged class because the types are managed (compiler error C3265). For example, I can't declare the following sink: static void Row_Deleting(Object* sender, System::Data::DataRowChangeEventArgs* e)
0
1934
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have these DLL interoperate with managed code. Among others things, the managed code need to be able to register for notification with the boost signals. I've tried different approaches (trying to register a pinned delegate with the boost::signal, etc...),
19
3472
by: Heidi Hundåla | last post by:
Hi ! I have a Wep App in C#. Page_Unload fires after Page_Load, and it seems totally unreasonable when you want to use this event when you _leave_ the page. In my project we wanted to use the Page_Unload - event to clean up the Session variables, but when it turns out that it fires before the end, it screws up the code, and
6
1783
by: Charles Law | last post by:
I have a class, which implements an interface. Let's say, that the interface looks something like Public Interface IEventSinks Sub ValueChanged(sender As Object, e As ValueChangedEventArgs) Sub StateUpdated(sender As Object, e As StateUpdatedEventArgs) End Interface In practice, the interface contains many more event handlers like this, but you get the picture.
1
1971
by: MLM450 | last post by:
I have created a .NET component in C# that has 2 interfaces. One is an incoming interface with methods being exposed to COM-aware clients. The other is an outgoing event interface that the unmanaged C++ sink implements. Here is the C# code: using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Reflection; using System.Diagnostics;
6
3781
by: Carmon | last post by:
I am using Managed C++ with a CFormView and a MaskedTextBox and have used MAKE_DELEGATE to sink the LostFocus event of this control. I have other events I've sinked off this control and they all work fine, however, the LostFocus does not fire. I found Scribble online and they do the same thing I did, however, when I used this code in Visual Studio 2005 the LostFocus event didn't get fired either.
1
3502
by: Apu Nahasapeemapetilon | last post by:
Hello and thank you in advance for your help. Can anyone think of a reason why this code would work properly on one PC, but not another? I've got a System.Windows.Forms.UserControl that products events which I want to consume (sink) within Internet Explorer. I'm following the instructions at: ms-http://support.microsoft.com/default.aspx?kbid=313891.
6
1594
by: fshawish | last post by:
Hello all, I have a C# Class Lib that exposes a public events, methods and properties. I am referencing this ClassLib from an MFC DIalog app that is compiled with /CLR. I use gcroot<T> to create and connect and call the method in the C# Class Lib w/o problems. However, I am having a hard time sinking the C# events in my managed C++ app. I am using .NET 1.1. Note that I can do this through COM Interop; however, I am would prefer
7
5131
by: Don | last post by:
Getting errors after following the MSDN article on using VB.NET (and VS2005) for "Implementing a Managed OnSave Event Sink" for Exchange Server 2007. Not sure, but part of the problem may be that it's the 64-bit version of Exchange 2007 installed on Windows Server 2003 Enterprise x64, while the Exchange 2007 SDK samples seem mostly geared toward 32-bit. Even at that, I was able to build the TLB and install it into COM+ Component Services,...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.