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/csh arp/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 (www.albaspectrum.com), he is Dexterity, SQL, VB/C#.Net, Crystal Reports and Microsoft CRM SDK developer.

In The News:


pen paper and inkwell


cat break through


Intro to UNIX Shells

A UNIX Shell is in simplest terms, a command line... Read More

Understanding Document Management

The term "document management" and "paperless office" is the subject... Read More

Linux Secrets

The first thing that you will notice about Linux Red... Read More

Microsoft Great Plains Data Conversion ? Overview For Developer

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

Crystal Reports for Microsoft Great Plains ? Overview for Developer

Microsoft Great Plains is main accounting / ERP application... Read More

Microsoft Office Selecting Secrets

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

What is a Document Manager without Version History?

Document Manager and Version HistoryIn previous articles I have discussed... Read More

Recent Studies Show that 9 out of 10 PCs Are Infected with Spyware

Spyware and malware are large problems for Internet users today... Read More

Microsoft Great Plains Implementation & Customization: Computer Parts Retailer Example

Microsoft Great Plains fits to majority of horizontals and retail... Read More

Free Microsoft Word Online Training Tutorial Resources

Microsoft Word is one of the most popular office applications... Read More

Benefits of Shareware

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

What To Do When Windows Wont Boot

When Windows fails to boot it is normally caused by... Read More

Software Automation Helps Increase your Bottom Line

When you own a small business, time is money. And... Read More

Microsoft CRM Integration With Microsoft Office Documents ? Overview For System Integrator

Microsoft CRM is CRM application, maintained and supported by Microsoft... Read More

Screenplay and Script Writing Software

When it comes to screenplay software each screenwriter needs to... Read More

Software Development in 2005 - Back to the Future

2005 ? Back to the Future.What does the future hold?... Read More

How to Backup Windows XP Home Edition

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

Imagine if Everyone Working In Your Office Was In Synch?

Microsoft-Outlook is a pretty amazing program. So much more than... Read More

Inherent Dangers Of File Sharing Via The Internet.

Cyberspace has opened up a new frontier with exciting possibilities... Read More

Not All Project Management Software is Created Equal

The purpose of Project Management Software is to provide an... Read More

Microsoft CRM Customization - Processing In/Out-Going Email Messages

We would like to give you several situations, when you... Read More

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

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

Monitoring Software Can be Used for Spying as Well

We all already got used to computer monitoring both at... Read More

Adware and Spyware Blockers

The most important things you can do for your computer... Read More

Computer Based Language Development and Spell-checking

Language development computer: Computer-based method for aiding language development seems... Read More

Great Plains Dexterity History and Programming Overview

As of now - Great Plains Dynamics/eEnterprise is transformed/renamed into... Read More

Microsoft CRM for Large Corporation ? Security

Microsoft Business Solutions CRM proved to be reliable solution in... Read More

Brand Your Websites URL With a Favicon

Have you ever noticed that when you look at your... Read More

RFID: Strengthen the Position for SAP; United States

SAP Inc., a global leader in client/server enterprise application software... Read More

Things You Can Do With Windows XP!

Did you ever give a thought to the number of... Read More

Off The Record - Tips For Picking Recording Software

Need software to record your voice, streaming audio or musical... Read More

Microsoft Navision and Crystal Reports - An Overview

Microsoft Business Solutions ? Navision is an integrated solution for... Read More

Explore the Internet in a Whole New Way

For a long time now Microsoft's Internet Explorer has ruled... Read More