+1 vote

Hello,

I am using Mail.dll library to save email in Sql server database, I am saving almost all the information, I fetch an email and I can reply to this, working fine. when the other person will reply me back then how can I recognize the parent email and save this reply also. I am saving email object as EML also.

by (850 points)

2 Answers

0 votes
 
Best answer

If you pass the IMail object to the below function you will get the history of the Message ID's

Private Function GetMessageOriginalIDs(e As IMAIL) As String()
    '-- References header is where the MessageID history is kept
    For Each S As String In e.Headers.AllKeys
        If S.ToLower.Contains("references") Then
            Return e.Headers.Item(S).ToString().split"("< >")
            Exit For
        End If

    Next

    Return new string(){}

End Function

Sample usage:

    Dim OriginatingMessageId As String

    If GetMessageOriginalIDs(e).Count > 0 Then
        '-- Message ID should be in order of index
        OriginatingMessageId = GetMessageOriginalIDs(e)(1)
    End If

This should then give you the Id of the originating message that you can then retreive from the mailbox/database.

Hope this helps.

Gary

by (400 points)
selected by
Can you please write this c# syntax.
because I can't fine e.Headers.Item(S).ToString().split"("< >") in c#.
Thank you
I'm not a great fan of the C# syntax but I think it goes like this:

private string[] GetMessageOriginalIDs(IMAIL e)
    {
            Char delimiter = ' ';
            foreach (string S in e.Headers.AllKeys) {
        if (S.ToLower().Contains("references")) {
           return e.Headers[S].ToString().Split(delimiter);
           break;
    }

    }

            return new string[] { };

    }

Hope it helps.
It works super. Thank you :)
0 votes

Reply is going to have In-Reply-To header set to the message id of the original email.

References should contain message ids of all referenced messages.

You can use IMail.IsReply to identify if email is a reply at all. Then you can use IMail.InReplyTo to access In-Reply-To header (Message Id of the original email) and IMail.References to access References header. Use IMail.MessageId to access Message-ID header;

by (297k points)
I am storing Message-ID of original E-mail, and using IMail.IsReply to identify if this E-mail is a reply, when I get IsReplyTo then this message id is different which I have stored when I have read E-Mail first time.
In-Reply-To points to the replied message (not the first message in thread). If In-Reply-To is different (completely different id?) it means the message is not a reply to this message. Message-Ids and In-Reply-Tos are assigned by the client, so theoretically they can be assigned incorrectly, but I don't think that happens often.
Yes. But I want to identify replied message's parent Email which I have saved in Database, and Update Bodypart of Email. is there any thiing which remains same in original message and all its reply, or any other way to get this done. :)
No, there is no such thing. You can use References header - it should contain all message-ids of the conversation. Most reliable solution is to include special id in message subject, something like this: "RE: This is a subject [TH:12345]".
...