How to read only new content in VSTO Outlook MailItem?

I wrote a small C # VSTO add-in for Outlook 2003 that reads the body of emails as they are sent, looking for specific words. He is working right now to do this:

if (currentItem.Body.Contains("text to search for"))

... but checks the entire body of the email, not just the new message being sent.

Is there anyway that Outlook simply checks the contents of the new message being sent and, therefore, ignores the old email chain, which could also be there?

These messages can be in any format (HTML, Rich Text, Plain Text) and may or may not have earlier messages chained to them. It's just a productivity tool for me, so any hack that works is worth considering here.

Thanks!

+5
source share
2 answers

For the record, the solution that I decided best for me was to simply check the line starting with β€œFROM:”, Michael suggested. I stop looking for my text as soon as it is found. This has been working fine for me for a while.

Thanks for the answers and ideas, that's all.

Here is my code for reference:

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Dim theLine As String
    Dim aBody()
    Dim bFound As Boolean
    Dim ctr As Long

    aBody = Array(Split(Item.Body, vbNewLine))
    bFound = False

    For ctr = 0 To UBound(aBody(1))
        theLine = aBody(1)(ctr)
        If InStr(theLine, "From:") > 0 Then
            Exit For
        End If

        If InStr(UCase(theLine), "ATTACH") > 0 Then
            bFound = True
        End If

    Next

    If bFound Then
        If Item.Attachments.Count < 1 Then
            Dim ans As Integer

            ans = MsgBox("Do you really want to send this without any attachments?", vbYesNo)
            If ans = 7 Then
                Cancel = True
                Exit Sub
            End If
        End If
    End If

End Sub
+1
source

@ Corbin Mart has the best answer here Separate multiuser email using Mime Parsers

+1
source

All Articles