I need to read the contents of an email account in Exchange Server and check this against a separate email database in SQL server. I am able to read the contents of email account for an Exchange Server.
If there is an email which is not in the SQL server database, I need to insert this into the database.
One of the ways to determine if the email already exists in the database, is to add a extended or custom property, such as "UniqueId" to the email message and set it to a Guid.
Hence if this property is found in the email message - it means - this was visited by the code earlier and therefore it should exist in the SQL database.
How do I accomplish this?
You can use the PidTagSearchKey property which is already there on Messages and doesn't change when a message is moved https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagsearchkey-canonical-property. Otherwise create your own https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633654(v=exchg.80)