如何仅读取 VSTO Outlook MailItem 正文中的新内​​容?

发布于 2024-08-20 13:40:56 字数 362 浏览 4 评论 0原文

我为 Outlook 2003 编写了一个小型 C# VSTO 插件,它可以在发送电子邮件时读取电子邮件正文,查找某些单词。它现在正在执行以下操作:

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

...但是它会检查整个电子邮件正文,而不仅仅是正在发送的新消息。

无论如何,是否可以让 Outlook 仅检查正在发送的新邮件的内容,从而忽略其中可能存在的旧电子邮件链?

这些消息可以是任何格式(HTML、富文本、纯文本),并且可能包含也可能不包含任何早期消息。这对我来说只是一个生产力工具,因此任何有效的技巧都值得在这里考虑。

谢谢!

I've written a little C# VSTO add-in for Outlook 2003 that reads the body of emails as they are being sent, looking for certain words. It's working right now to do this:

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

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

Is there anyway to have Outlook just check the contents of the new message being sent, and so ignore the older email chain that might be in there too?

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

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与君绝 2024-08-27 13:40:56

@Corbin March 在这里有最好的答案 使用 Mime 解析器分隔多部分电子邮件

@Corbin March has the best answer here Separate a multipart email using Mime Parsers

玩世 2024-08-27 13:40:56

根据记录,我认为最适合我的解决方案是简单地检查以“FROM:”开头的行,Mikael 建议。一旦找到我的文字,我就停止搜索。这对我来说已经工作了一段时间了。

谢谢大家的回复和想法。

这是我的代码供参考:

    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

For the record, the solution I decided worked best for me was to simply check for a line starting with "FROM:", Mikael suggested. I stop searching for my text as soon as that is found. That's been working just fine for me for a while now.

Thanks for the responses and ideas, everyone.

Here's 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文