Removing Incoming Email in MS Exchange, C# Example

The purpose of one of our projects was MS Exchange handler for processing incoming email.

The basic source of knowledge was this article "Developing Managed Event Sinks/Hooks for Exchange Server Store using C#" by Logu Krishnan, published to the address http://www.codeproject.com/csharp/csmanagedeventsinkshooks.asp, and also examples from Microsoft Exchange SDK.

We utilized Synchronous Events and created the handler, which fires on OnSyncSave event. The handler creates activity record in Microsoft CRM and then removes the message in the Exchange database before the commitment:

public void OnSyncSave(IExStoreEventInfo pEventInfo, string bstrURLItem, int IFlags) { try { if (IFlags == ((int)EVT_SINK_FLAGS.EVT_SYNC_COMMITTED + (int)EVT_SINK_FLAGS.EVT_IS_DELIVERED)) {

ProcessMessage(pEventInfo, bstrURLItem, IFlags);

}

}

catch (Exception ex) {

log.Debug(ex.Message + " " + ex.StackTrace);

}

finally {

LogManager.Shutdown();

} }

For Exchange handlers debugging - it is the extremely convenient to use system log4net in RollingLogFileAppender or RemoteAppender modes (for multiple instance of COM + objects). You can read more on this subject here http://logging.apache.org/log4net/ To allow the handler incoming mail removal, it is necessary to give proper rights to the user, under which account the COM+ application runs the handler. These are rights on change of the information in user's boxes for whom it is registered (Windows 2003 Server: Active Directory Users and Computer -> Users -> Properties (for COM+ application account) -> Exchange Advanced -> Mailbox Rights). And now the code:

private void DeleteMessage(string bstrURLItem) { try {

ADODB.Connection oCn = new ADODB.Connection();

oCn.Provider = "exoledb.datasource";

oCn.Open(bstrURLItem, "", "", -1);

if(oCn.State == 1) {

log.Debug("Good Connection");

}

else {

log.Debug("Bad Connection");

}

ADODB.Record rec = new ADODB.Record();

rec.Open(bstrURLItem, oCn,

ADODB.ConnectModeEnum.adModeReadWrite,

ADODB.RecordCreateOptionsEnum.adFailIfNotExi sts,

ADODB.RecordOpenOptionsEnum.adOpenSource,

"", "");

rec.DeleteRecord(bstrURLItem, false);

rec.Close();

oCn.Close();

rec = null;

oCn = null;

}

catch (Exception ex) {

log.Debug(ex.Message + " " + ex.StackTrace);

} }

Happy customizing! Boris Makushkin

Boris Makushkin is Software Engineer in Alba Spectrum Technologies ? USA nationwide Microsoft CRM, Microsoft Great Plains customization company, based in Chicago, Boston, San Francisco, San Diego, Los Angeles, Houston, Atlanta, New York, and Miami and having locations in multiple states and internationally (http://www.codeproject.com/csharp/csmanagedeventsinkshooks.asp), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.

move out cleaning service Glencoe ..
In The News:

Scammers use fake DocuSign emails claiming Apple Pay charges to steal personal information using fraudulent phone numbers and fake receipts.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Farmers Insurance confirms data breach affecting over 1.1 million customers nationwide, exposing customer info including addresses.
The iconic Mary Kay pink Cadillac goes electric with the Cadillac Optiq, available only to the company's top 1% of sales force performers.
Cybercriminals abuse trusted Intel driver to gain kernel access and shut down Windows Defender, enabling undetected malware deployment since July 2025.
Using email aliases for online shopping and subscriptions can protect your privacy by preventing companies from linking your activity across websites.
New research shows AI overlap does not equal job replacement, with knowledge-based roles seeing most integration while physical jobs remain least affected.
Scammers target seniors who avoid social media by exploiting public records like obituaries and real estate filings to steal personal information and money
Recovery team in Italy use AI-enabled drones to detect missing hiker's red helmet, leading to successful recovery after months of ground searches
Google Salesforce system breach exposes business data while scammers use incident to target users with fake security calls and phishing attempts.
Google announces Pixel 10 lineup with Tensor G5 chip and Gemini Nano AI, introducing Magic Cue, Pro Res Zoom up to 100x and satellite emergency support features.
C San Diego study reveals 86% of school safety companies monitor students 24/7 on personal devices, raising privacy concerns.
Users can now add their favorite outlets' coverage to the Top Stories section of Google search results by utilizing the 'preferred sources' feature. With just a few clicks, you can add Fox News.
Stay up to date on the latest AI technology advancements and learn about the challenges and opportunities AI presents now and for the future.
Interstellar object 3I/ATLAS shows an unexpected frontal glow that Harvard's Avi Loeb says cannot be explained by sunlight reflection or standard cometary outgassing.
Receiving order confirmations for purchases you never made could mean your email address is being exploited in fraud operations targeting multiple retailers.
First wireless brain implant works with Apple's official protocol, enabling hands-free control of iPhones, iPads and Vision Pro through thought alone.
Data brokers sell personal details that scammers use to target retirement funds through fake financial advisor calls and convincing phishing attempts
Ten innovative tech solutions from gait sensors to smart pill dispensers help adults 65+ track fall risks and prevent injuries before they happen.
Meta AI internal documents revealed chatbots were allowed to flirt with children and engage in romantic conversations until the company was exposed by Reuters.
ChatGPT will avoid giving direct mental health advice under new OpenAI rules following instances where the AI model provided harmful or misleading responses.
Your phone tracks you in more ways than that little GPS icon suggests. Here’s how to find and clear hidden location logs on iPhone and Android.
Authorities in France and the Netherlands have been notified. Meanwhile, impacted customers are being told to stay alert.
Apple just rolled out a redesigned Blood Oxygen feature to specific models, following a recent victory in a legal dispute.
Kidney dialysis provider DaVita experienced a ransomware breach by the Interlock gang affecting 916,000 people in the second-largest U.S. healthcare attack of 2025.

How to Backup Windows XP Home Edition

Your computer cost you from hundreds to thousands of dollars,... Read More

Great Plains Sales Order Processing and Invoicing Modules ? Tips For Consultants

We'll give you non formal view, based on our consulting... Read More

Great Plains Dexterity ? Microsoft Great Plains Customization Overview

Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More

Screenshots Vista Windows

Features Additionally, Vista will include many other new features.Aero Vista... Read More

Integrating Microsoft Great Plains Accounting/ERP: RMS, CRM, eCommerce, Lotus Domino ? overview

Microsoft Business Solutions Great Plains has substantial market share among... Read More

Introduction To ISDN, Part III: PAP

Introduction To ISDN, Part III: Configuring PPP PAP AuthenticationNow we... Read More

SQL Administrator Skills Required to Support Microsoft Great Plains

Microsoft Great Plains is becoming more and more popular and... Read More

Know-how in Microsoft Publisher

For those who still don't know, Microsoft Publisher helps computer... Read More

Microsoft CRM in Latin America: Implementation, Customization, Support ? Overview for Consultant

Microsoft Business Solutions CRM is present several years on the... Read More

Microsoft Great Plains - Typical Problems And Fixes ? Overview For IT Administrators

How to delete the user? This is the first problem... Read More

Programming Language Migration Path

While I was preparing some personal background information for a... Read More

Great Plains Accounting Migration to Microsoft Great Plains - Overview for IT Specialist

This is a short article, written in question/answer/FAQ style to... Read More

Microsoft Great Plains version 8.5: Upgrade, Customization, VBA, Crystal Reports - Highlights

Microsoft Great Plains is one of the Microsoft Business Solutions... Read More

Reporting Tools for Microsoft Great Plains ? Overview For Developers

Looks like Microsoft Great Plains becomes more and more popular,... Read More

Fast Car Knoppix

Small can be beautiful! Working with Knoppix for the past... Read More

How To Avoid Getting Hooked By Pfishing

"Pfishing", sometimes spelled "Phishing", is a word that's used to... Read More

Can You Calculate Complex Financial Calculations?

Are you a whiz at calculating financial information? Not the... Read More

Cisco Certification: Introduction To ISDN, Part IV

In part III of this ISDN primer, we learned that... Read More

Microsoft Great Plains Food Processing ? Implementation & Customization Highlights

Microsoft Great Plains might be considered as ERP platform to... Read More

Enterprise Resource Planning Overview

ERP (Enterprise Resource Planning) Overview covers What is ERP, Brief... Read More

Microsoft Business Solutions VAR/Partner Selection ? Overview for IT Director/Manager/Controller

Microsoft Great Plains and Microsoft CRM become more and more... Read More

Adware, What Is It?

Adware is a type of Spyware program that displays some... Read More

Microsoft Great Plains PM: Payables Management

Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More

Microsoft Great Plains Accounting/ERP Implementation ? Finance Industry Customization Example

Microsoft Business Solutions Great Plains is very generic accounting application... Read More

Microsoft Great Plains Nationwide Remote Support

ERP Consulting industry is on the way to serve clients... Read More

house cleaning company Bannockburn ..