获取特定于Outlook中的回复的MailItem

时间:2014-07-07 14:17:08

标签: vb.net outlook-addin mailitem

我正在创建一个Outlook插件,当用户点击“回复”任何电子邮件时,需要更改MailItem的多个属性。我现在正在做这样的事情:

Private Sub PrepareEmailForReply(ByVal MailItem As Outlook.MailItem, ByVal FromAddress As String)
    If Not ReplyDictionary.ContainsKey(MailItem.ConversationID) Then
        ReplyDictionary.Add(MailItem.ConversationID, FromAddress)
        AddHandler MailItem.Reply, Sub()
                                               InReply = True
                                   End Sub
    End If
End Sub

Private Sub CurrentExplorer_SelectionChange() Handles CurrentExplorer.SelectionChange
    Dim SelectedFolder As Outlook.MAPIFolder = Me.Application.ActiveExplorer().CurrentFolder
    Try
        If Me.Application.ActiveExplorer.Selection.Count > 0 Then
            Dim SelectedObject As Object = Me.Application.ActiveExplorer.Selection.Item(1)
            If (TypeOf SelectedObject Is Outlook.MailItem) Then
                Dim MailItem As Outlook.MailItem = TryCast(SelectedObject, Outlook.MailItem)

                If (CurrentEmail IsNot MailItem) Then
                    Output.AddInfo(MailItem.ConversationTopic)

                    CurrentEmail = MailItem
                    If (InReply) Then
                        Output.AddInfo("> In Reply")
                        If ReplyDictionary.ContainsKey(MailItem.ConversationID) Then
                            MailItem.Subject = "Testing Reply Email"
                        End If
                    Else
                        Output.AddInfo("> In MailItem")
                        For Each Recipient As Outlook.Recipient In MailItem.Recipients
                            Dim CurrentEmailAddress As String = Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress.ToLower.Trim()
                            If ListeningUsers.Contains(CurrentEmailAddress) Then
                                PrepareEmailForReply(MailItem, CurrentEmailAddress)
                                Exit For
                            End If
                        Next
                    End If
                    InReply = False
                End If
                End If
        End If
    Catch ex As Exception
    End Try
End Sub

一切正常,但是“MailItem.Subject =”测试回复电子邮件“行上的MailItem实际上并不对应回复电子邮件,因此主题不会被更改。

如何获取回复电子邮件的MailItem,以便我可以更改主题?

ListeningUsers变量是List(of String),其中包含有效的电子邮件列表。它包含当前用户。

**编辑:**

这是我在MailItem.Reply事件调用中添加了一些更改的地方:

        AddHandler MailItem.Reply, Sub()
                                       Dim CurrentInspector As Outlook.Inspector = Globals.ThisAddIn.Application.ActiveInspector()
                                       Dim ReplyMailItem As Outlook.MailItem = TryCast(CurrentInspector.CurrentItem, Outlook.MailItem)
                                       If (ReplyMailItem IsNot Nothing) Then
                                           MsgBox("1: " & ReplyMailItem.Subject & " - " & ReplyMailItem.EntryID)
                                           Return
                                       End If

                                       CurrentInspector = CurrentExplorer.ActiveInlineResponse
                                       ReplyMailItem = TryCast(CurrentInspector.CurrentItem, Outlook.MailItem)
                                       If (ReplyMailItem IsNot Nothing) Then
                                           MsgBox("2: " & ReplyMailItem.Subject & " - " & ReplyMailItem.EntryID)
                                       End If
                                   End Sub

如果我在外部窗口中打开电子邮件然后单击回复,则会出现第一个msgbox,但是,如果我单击回复Outlook内部的电子邮件(不是弹出窗口),则会显示第二个{{1}应该出现,但它没有。

1 个答案:

答案 0 :(得分:1)

获取回复电子邮件并非易事。多年来我一直在窃听Outlook产品团队,在MailItem对象上包含一个ReplyItem属性,但他们还没有听过。

问题是用户可以回复选定的电子邮件或打开的电子邮件。您始终可以监视Inspectors.NewInspector并检查新电子邮件的空白MailItem.EntryID值,并确保MailItem.Recipients.Count> 0.然后你就知道它是一个回复,然后你必须通过Inspectors获取Explorer.Selection OR循环(找到打开的电子邮件窗口)。然后,您必须将所选/打开的电子邮件中的ConversationID与新的撰写电子邮件进行匹配。