/// <summary> /// Archive this email item to CRM. /// </summary> /// <param name="olItem">The email item to archive.</param> /// <param name="reason">The reason it is being archived.</param> /// <returns>A result object indicating success or failure.</returns> public static ArchiveResult Archive(this Outlook.MailItem olItem, EmailArchiveReason reason, string excludedEmails = "") { ArchiveResult result; Outlook.UserProperty olProperty = olItem.UserProperties[CrmIdPropertyName]; if (olProperty == null) { result = olItem.AsArchiveable(reason).Save(excludedEmails); if (result.IsSuccess) { olItem.Categories = string.IsNullOrEmpty(olItem.Categories) ? SuiteCRMCategoryName : $"{olItem.Categories},{SuiteCRMCategoryName}"; olItem.EnsureProperty(CrmIdPropertyName, result.EmailId); } } else { result = ArchiveResult.Success(olProperty.Value, new[] { new AlreadyArchivedException(olItem) }); } return(result); }
/// <summary> /// Archive this email item to CRM. /// </summary> /// <param name="olItem">The email item to archive.</param> /// <param name="reason">The reason it is being archived.</param> /// <param name="moduleKeys">Keys (standardised names) of modules to search.</param> /// <param name="excludedEmails">email address(es) which should not be linked.</param> /// <returns>A result object indicating success or failure.</returns> public static ArchiveResult Archive(this Outlook.MailItem olItem, EmailArchiveReason reason, IEnumerable <CrmEntity> moduleKeys, string excludedEmails = "") { ArchiveResult result = olItem.AsArchiveable(reason).Save(moduleKeys, excludedEmails); if (result.IsSuccess) { try { if (string.IsNullOrEmpty(olItem.Categories)) { olItem.Categories = SuiteCRMCategoryName; } else if (olItem.Categories.IndexOf(SuiteCRMCategoryName) == -1) { olItem.Categories = $"{olItem.Categories},{SuiteCRMCategoryName}"; } olItem.EnsureProperty(CrmIdPropertyName, result.EmailId); } catch (COMException cex) { ErrorHandler.Handle("Could not set property while archiving email", cex); } } return(result); }