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
应该会出现,但它不会出现。