1

How to compare e-mail messages without using the body of the message?

For example:

  • John sent a message to Mary and "save" this message in my addin.
  • Both have the same addin.
  • When Mary receives the message, this message must be categorized because John already "save" the message.

How to identify that the message that Mary received is the same as the message that John sent("save") without using the body of the message?

Currently this is working as follows, a HASH is made with the following information:

  • Sender
  • Addressee
  • Subject
  • Message Body Text

This Hash is stored in the database, when Mary's Outlook triggers the event of the new message, a HASH with the same information is generated and compared in the database to see if it should be categorized or not.

The problem is that depending on the body size of the message, it is not performatic, it takes a long time to get the body of the message through the MailItem.Body property.

The purpose of not using the body of the message is solely to increase performance.

public string GetAssinatura(Outlook.MailItem email)
    {
        try
        {

            string corpoEmail = email.Body;//this is not performatic with big messages

            var hash = GenerateHash(corpoEmail); 
        }
    }

Conversation participants can reply or forward the message, so Outlook and most of the most frequently used e-mail clients change the subject to a default, Re: Subject for example. Therefore, it is not possible to only have a hash of the participants and the subject.

Anderson Rissardi
  • 2,377
  • 1
  • 16
  • 21
  • I assume sender+addressee+subject isnt enough. – Kenneth Garza Sep 11 '18 at 19:21
  • @KennethGarza isnt, my example was a bad example, is more like, if the mail is sent from a person from company A to a person in company B, both have de same Addin(database) I need to identify that condition.. If use sender+addressee+subject, 2 messages with the same info will return the same hash... – Anderson Rissardi Sep 11 '18 at 19:37
  • i suspected that was the case... can't seem to think of anything. I would suggest posting a code example of what is not performant. There might be other options for what you're attempting to get. – Kenneth Garza Sep 11 '18 at 19:45
  • Sender/Recipients/Subject are just not unique enough. I don't think you can avoid using the Body. – Dmitry Streblechenko Sep 11 '18 at 22:09
  • Hi @DmitryStreblechenko , It is not enough because when replying and forwarding a message Outlook always changes the subject to the same pattern. Ex: RE: Subject. In these cases the hash would be the same as another, my application believes that the message has already been stored. I need something that I can get both from the sender and recipient. – Anderson Rissardi Sep 12 '18 at 12:22
  • The ideal would be to use the Message-ID, but unfortunately a) you're not guaranteed that it's generated *before* the message is sent and b) it's not readily surfaced in Outlook. – Damien_The_Unbeliever Sep 12 '18 at 12:35
  • I already tried MailItem.ConversationID and MailItem.Size, but both data are diferents in sender Outlook and in Addressee Outlook... I'm looking for something like that, but tha its equals.. – Anderson Rissardi Sep 12 '18 at 12:41

1 Answers1

2

Using the property:

MailItem.SentOn

It's possible generate that hash. The sender Outlook only will have that info after send the message. So the code must run when a new item is add in the Item_Send folder.

Anderson Rissardi
  • 2,377
  • 1
  • 16
  • 21