我有一个Outlook插件,处理某些类型的已发送电子邮件。对于某些类型的电子邮件用户必须填写一些信息的表格,然后应用程序将电子邮件作为MSG导出到文件系统中的目录树VSTO Outlook加载项 - 处理程序发送邮件不总是工作
我有一个功能区,带有一个按钮,用于为发送的电子邮件设置一个标志(userproperty)所以插件知道哪些邮件必须保存:
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
Dim oProperties As Outlook.UserProperties
Dim oProperty As Outlook.UserProperty
oMail = Globals.ThisAddIn.Application.ActiveInspector.CurrentItem
If Not oMail Is Nothing Then
oProperties = oMail.UserProperties
oProperty = oProperties.Add("SALVARAPIGES", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olYesNo)
oProperty.Value = True
oMail.Save()
oMail.Send()
Else
MsgBox("Err")
Exit Sub
End If
End Sub
在插件启动时,我有(摘录):
Private Sub ThisAddIn_Startup() Handles Me.Startup
Dim sentItems As Outlook.Items
Dim sentFolder As Outlook.Folder
Dim paisapiges As String
Dim aux As String()
Dim ns As Microsoft.Office.Interop.Outlook.NameSpace
apigesIsLoaded = True
'adiciono um trigger para que sempre que for enviado um email e for do tipo SALVARAPIGES, ele fará o tratamento de salvar o email.
sentFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
sentItems = sentFolder.Items
AddHandler sentItems.ItemAdd, AddressOf itemadd
和我itemadd常规:
Sub itemadd(ByVal NewEmailItem As Object)
Dim oProperties As Outlook.UserProperties
Dim salvaApiges As Boolean
Dim sentMessageItem As Outlook.MailItem = CType(NewEmailItem, Outlook.MailItem)
Dim mainForm As New formSalvarApiges()
salvaApiges = False
If Not sentMessageItem Is Nothing Then
oProperties = sentMessageItem.UserProperties
For Each pr As Outlook.UserProperty In oProperties
If pr.Name = "SALVARAPIGES" Then
salvaApiges = True
Exit For
End If
Next
If salvaApiges Then
mainForm.txtAssunto.Text = sentMessageItem.Subject
mainForm.sAction = "Acao01"
mainForm.sEntryId = sentMessageItem.EntryID
mainForm.ShowDialog()
mainForm.Close()
End If
End If
End Sub
正如您可以在电子邮件中包含此“SALVARAPIGES”用户属性时所看到的那样,它必须保存到目录树中的MSG中。但有一半的用户表示这不起作用(表格不是弹出窗口),但每当我测试它时,它都可以正常工作。我对VSTO及其背后的所有概念都很陌生......任何人都可以指出我的方向吗?
我已经尝试使用NameSpace.SendAndReceive方法,但他们不断抱怨。
在此先感谢!
感谢您的更完整的答案,但第一个答案是仍然不足以解决问题,所以我会给他信贷。但是非常感谢你! – fferrandini