If you need to configure a specific Microsoft Exchange folder to track the emails and run a workflow process configured in crm, it is possible trough few lines of code.
Let's assume that you have configured a folder in the Microsoft Exchange to keep emails sent by a specific (individual contact or company).
The code needed for this is:
To create and manage folder-level tracking rules:
// Create a folder-level tracking rule
MailboxTrackingFolder newTrackingFolder = new MailboxTrackingFolder();
// Set the required attributes newTrackingFolder.ExchangeFolderId = "123456";
// Sample value. Retrieve this value using Exchange Web Services (EWS)
newTrackingFolder.MailboxId = new EntityReference(Mailbox.EntityLogicalName, _mailboxId);
// Set the optional attributes
newTrackingFolder.RegardingObjectId = new EntityReference(Account.EntityLogicalName, _accountId); newTrackingFolder.RegardingObjectId.Name = _accountName;
newTrackingFolder.ExchangeFolderName = "Sample Exchange Folder";
// Execute the request to create the rule
_folderTrackingId = _serviceProxy.Create(newTrackingFolder); Console.WriteLine("Created folder-level tracking rule for '{0}'.n", _mailboxName);
MailboxTrackingFolder newTrackingFolder = new MailboxTrackingFolder();
// Set the required attributes newTrackingFolder.ExchangeFolderId = "123456";
// Sample value. Retrieve this value using Exchange Web Services (EWS)
newTrackingFolder.MailboxId = new EntityReference(Mailbox.EntityLogicalName, _mailboxId);
// Set the optional attributes
newTrackingFolder.RegardingObjectId = new EntityReference(Account.EntityLogicalName, _accountId); newTrackingFolder.RegardingObjectId.Name = _accountName;
newTrackingFolder.ExchangeFolderName = "Sample Exchange Folder";
// Execute the request to create the rule
_folderTrackingId = _serviceProxy.Create(newTrackingFolder); Console.WriteLine("Created folder-level tracking rule for '{0}'.n", _mailboxName);
You can create a maximum of 25 folder-level tracking rules per mailbox.
To Retrieve folder-level tracking rules for a mailbox:
| // Retrieve the folder mapping rules for a mailbox RetrieveMailboxTrackingFoldersRequest req = new RetrieveMailboxTrackingFoldersRequest { MailboxId = _mailboxId.ToString() }; RetrieveMailboxTrackingFoldersResponse resp = (RetrieveMailboxTrackingFoldersResponse_serviceProxy.Execute(req); Console.WriteLine("Retrieved folder-level tracking rules for {0}:", _mailboxName); int n = 1; foreach (var folderMapping in resp.MailboxTrackingFolderMappings) { Console.WriteLine("tRule {0}: '{1}' is mapped to '{2}'.", n, folderMapping.ExchangeFolderName, folderMapping.RegardingObjectName); n++; } |
Code in here from CRM 2015 SDK.
Hope this can be helpful.
No comments:
Post a Comment