0

MailItem我正在制作一个 Outlook 插件,当用户单击“回复”任何电子邮件时,它需要更改 a 的几个属性。我目前正在做这样的事情:

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 = "Testing Reply Email" 行上的 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 内的电子邮件(不是弹出窗口),那么第二个msgbox应该会出现,但它不会出现。

4

1 回答 1

1

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

问题是用户可以回复选定的电子邮件或打开的电子邮件。您始终可以监控 Inspectors.NewInspector 并检查新电子邮件的空白 MailItem.EntryID 值,并确保 MailItem.Recipients.Count > 0。然后您将知道这是回复,然后您必须获取 Explorer。选择或循环检查器(以查找打开的电子邮件窗口)。然后,您必须将所选/打开的电子邮件上的 ConversationID 与新的撰写电子邮件相匹配。

于 2014-07-08T19:55:42.883 回答