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.

custom home cleaning Wilmette ..
In The News:

Unlike robotaxi competitors, Tensor focuses on consumer-owned self-driving cars that adapt to highways and urban roads with full redundancy systems for safety.
Medicare scams cost $54 billion in 2024 as fraudsters target beneficiaries with fake calls demanding payments and personal information to steal benefits.
Scammers create fake Evite invitations that mimic legitimate event emails, requiring users to verify senders and use antivirus software for protection.
The new Apple Watch hypertension feature passively monitors blood pressure patterns over 30 days using sensors to detect chronic high blood pressure signs.
Chrome extension spyware disguised as a free VPN service highlights security risks after it captured private browsing data from trusted sites.
New research shows how fatty acids in cooking oil can safely dissolve and recover silver from circuit boards without harmful chemicals or environmental damage.
The Fox News AI newsletter gives you information on the latest AI technology advancements, and about the challenges and opportunities AI presents now and for the future.
Anthropic investigates alarming AI abuse case where hacker automated entire cybercrime campaign using Claude, stealing sensitive data from defense and healthcare firms.
TikTok, Meta and YouTube restrict Charlie Kirk shooting videos with age gates and warnings while X faces criticism for allowing continued circulation.
Cybercriminals use fake troubleshooting websites to trick Mac users into running terminal commands that install Shamos malware through ClickFix tactics.
San Francisco startup Fable launches Showrunner, an AI platform dubbed the 'Netflix of AI' that generates animated episodes from text descriptions with Amazon support.
Apple raised iPhone prices for some models despite receiving tariff relief from President Donald Trump, with the new lineup starting at $799 for the base model.
A two-story 3D concrete printed home in Western Australia demonstrates faster construction methods that could reshape American housing amid rising costs.
Credit scores remain important during retirement for insurance rates and housing applications, while seniors become prime targets for identity theft and financial scams.
Scammers now send unexpected packages with QR codes that redirect victims to fraudulent websites or download malicious software to steal sensitive information.
Meeting AI tools record private conversations alongside work discussions, creating privacy risks that can be managed with proper settings and awareness.
Hotel privacy concerns are valid but rare, with methods to detect hidden tech using smartphone flashlights, mirror tests and scanning apps.
Improve your Wi-Fi speed and reliability with 10 simple router optimization tips that don't require special apps or expensive subscriptions.
A Columbia University breach exposed names, Social Security numbers and academic records of nearly 869,000 people, with notifications beginning in August.
Rental car drivers use AI-powered apps like Proofr to protect themselves from unfair damage fees as major companies deploy automated inspection tools.
Fox News' AI newsletter brings you the latest on technology advancements around artificial intelligence.
OnTrac data breach between April 13-15, 2025, exposed personal information of over 40,000 people including Social Security numbers and medical records.
A woman named Wika announces her engagement to an AI chatbot sparking worldwide debate about virtual relationships and technology.
The notorious people search site National Public Data relaunches despite a previous breach affecting 3 billion individuals, raising fresh privacy concerns.
Revolutionary TRAUMAGEL gel controls life-threatening bleeding from gunshot wounds and traumatic injuries, helping first responders prevent prehospital deaths.

Spyware: What It Is and How to Combat It

Spyware is software or hardware installed on a computer without... Read More

Microsoft Office Selecting Secrets

Stop the Runaway MouseWhat's the "runaway mouse?" You've seen it...you... Read More

Free Software for Newbies and Web Developers

Here is some free software tools to help you build... Read More

Internet Security Threats: Who Can Read Your Email?

Before being able to choose a secure Internet communication system,... Read More

IT Department Skills to Support Microsoft Great Plains and Microsoft CRM

Microsoft Great Plains as ERP and Microsoft CRM as... Read More

Cisco Certification: Introduction To ISDN, Part V

The major reason I recommend getting your hands on real... Read More

3 Reasons Why Medical Billing Software is Leading the Way

Since technology changes so quickly, it is hard to begin... Read More

Constructionalist Parsing - Deciphering Natural Language

The research in the field of Natural Language Processing usually... Read More

Backing Up And Restoring Your MySQL Database

If you've been using MySQL database to store your important... Read More

S is for Spying, Surveillance -- and for Software as Well

Words we choose to describe things and phenomena often show... Read More

New SQL Delta Version 3.1

COMMAND LINE FUNCTIONA powerful command line script processor has been... Read More

Accessing XML Using Java Technologies

The most important benefit of XML is its simplicity. Though... Read More

Need of Document Management System (DMS)

Document Management or Enterprise Information Management is perhaps one of... Read More

The Bluebird Project

The objective for Zandi Digital is to make available clever... Read More

Your Computer May Be Infected, Heres How To Check (NOT about virus)

NOTE: Please take time to read on - it may... Read More

Managing Stress in the Computer Industry - Five Steps to a Stress-free Life

It would be easy to think, like most people apparently... Read More

Microsoft CRM Implementation & Customization: MS CRM Fax Gateway

With this small article we are continuing Microsoft Business Solutions... Read More

Microsoft Great Plains on Ctree or Pervasive SQL ? What to Do ? Tips for IT Manager

As you probably know, when Microsoft purchased Great Plains Software... Read More

Assertion in Java

Assertion facility is added in J2SE 1.4. In order to... Read More

Benefits of Shareware

Shareware has been fighting the stigma of being misunderstood for... Read More

Microsoft CRM Integration with Microsoft Retail Management System (RMS) ? Overview

Microsoft Client Relation Management system (Microsoft CRM) and Microsoft RMS... Read More

Microsoft Great Plains Integrations - Tips for Developer

In this short FAQ style article we would like to... Read More

Microsoft Great Plains FA: Fixed Assets ? Overview For Consultant

Great Plains Fixed Assets Management module is a robust tool... Read More

A Guide To Purchasing Professional XP Icons Online And Enhancing Your Applications

Icons are used everywhere; right from software applications, to internet... Read More

Software Upgrades Arent Always the Best Move

When my daughter was getting into AOL instant messaging (AIM)... Read More

same day cleaning service Morton Grove ..