|
Microsoft CRM has variety of customizations options and tools. The official and
the most popular is Microsoft CRM SDK: collection of C#.Net and partially
VB.Net classes, methods and code samples. Here we would like to give you more
complex case, when you call CRM SDK customization from custom MS Exchange event
handler – we are improving the functionality of MS Exchange – MS CRM connector.
Imagine the case when you want outgoing email to be captured and placed into
CRM, attached to Contact, Account or Lead they should belong to. If this is
realized – your salespeople can use any email tool to send their messages, they
do not have to do it in CRM or Outlook Client for CRM.
MS Exchange OnSyncSave database event can’t work with Sent folder – it doesn’t
fire when message goes to Sent folder. The reason is described here:
. Event handler works OnArrival event:
void ISMTPOnArrival.OnArrival(CDO.IMessage msg, ref CDO.CdoEventStatus
EventStatus)
{
log = LogManager.GetLogger(typeof(ShieldsUp));
DOMConfigurator.Configure(new FileInfo(Environment.SystemDirectory +
"/CustomerApp/log.config"));
try {
ProcessMessage(msg);
}
catch (Exception ex) {
log.Debug(ex.Message + "
" + ex.StackTrace);
}
finally {
LogManager.Shutdown();
}
}
The class:
// ComVisible enables COM visibility of this class. The default is true.
// Explicitly setting this attribute to true, as shown below, is useful
// if ComVisible is set to false for the namespace and you want the
// classes to be accessible individually.
[ComVisible(true)]
public class ShieldsUp: CDO.ISMTPOnArrival
{
Next the handling works similar to SyncSave handler:
private void ProcessMessage(CDO.IMessage msg)
{
string sFrom;
string sTo;
string sSubject;
string sBody;
string sSensitivity;
try
{
log.Debug("Firing Up ProcessMessage()");
sSubject = msg.Subject;
sBody = msg.TextBody;
sFrom = msg.From;
sTo = msg.To;
if (msg.Fields["urn:schemas:mailheader:sensitivity"].Value != null)
sSensitivity =
msg.Fields["urn:schemas:mailheader:sensitivity"].Value.ToString();
else
sSensitivity = "Normal";
log.Debug("Message From: " + sFrom);
log.Debug("Message To: " + sTo);
log.Debug("Subject: " + sSubject);
log.Debug("Sensitivity: " + sSensitivity);
log.Debug("Body: " + sBody);
|