我们创建了一个Outlook VSTO加载项,在一夜之间让Outlook空闲后停止工作。当我们第二天返回工作时,加载项仍显示为已启用但不再有效。您重新启动Outlook,它再次正常工作。我们有大约35个用户在同一个收件箱中工作(Outlook 2013)。所有在Exchange Server上以实时模式设置相同的方式,其个人电子邮件作为默认发件人和共享"工作"电子邮箱代表他们的个人。下面是设计用于标记每封电子邮件的VB代码,用户删除或移动到另一个文件夹,文本为" Email Handled By(用户名)At(现在)。我们愿意接受其他建议。只是想找到一种方法来跟踪谁删除/处理电子邮件。我们知道我们应该转向CRM类型系统(每天发送5,000多封电子邮件)。提前感谢您的帮助。
'Allow forms to be used, Future Possible enhancements
Imports System.Windows.Forms
'Allow use of the outlook interperability (Outlook functions
Imports Microsoft.Office.Interop.Outlook
Imports System.Data
Imports System.Data.SqlClient
Public Class ThisAddIn
'Create public variable holders
'Variable to hold the folder items (Inbox)
Public WithEvents olkFolder As Outlook.Folder
'Variable to hold the folder Items (Deleted Item
Public WithEvents olkFolderItems As Outlook.Folder
'Variable to hold the item.
Public WithEvents olkItems As Outlook.Items
Public WithEvents olkFolderCT As Outlook.Folder
Public WithEvents olkFolderItemsCT As Outlook.Folder
Public WithEvents olkItemsCT As Outlook.Items
Public WithEvents olkFolderNJ As Outlook.Folder
Public WithEvents olkFolderItemsNJ As Outlook.Folder
Public WithEvents olkItemsNJ As Outlook.Items
Public WithEvents olkFolderOld As Outlook.Folder
Public WithEvents olkFolderItemsOld As Outlook.Folder
Public WithEvents olkItemsOld As Outlook.Items
'Function that fires upon startup of the plugin
Private Sub ThisAddIn_Startup(sender As Object, e As EventArgs) Handles Me.Startup
'This is used to force the program to continue in case an operator does not have an inbox with a name of ROCLI
On Error Resume Next
'Set the variable to the Inbox Folder
olkFolder = Application.Session.Folders("ROCLI").Folders("Inbox")
'Set the variable to the Deleted Folder
olkFolderItems = Application.Session.Folders("ROCLI").Folders("Deleted Items")
'Set the items, to the items in the Inbox
olkItems = Application.Session.Folders("ROCLI").Folders("Inbox").Items
'Set the variable to the Inbox Folder
olkFolderCT = Application.Session.Folders("ROCCTHV").Folders("Inbox")
'Set the variable to the Deleted Folder
olkFolderItemsCT = Application.Session.Folders("ROCCTHV").Folders("Deleted Items")
'Set the items, to the items in the Inbox
olkItemsCT = Application.Session.Folders("ROCCTHV").Folders("Inbox").Items
'Set the variable to the Inbox Folder
olkFolderNJ = Application.Session.Folders("ROCNJ").Folders("Inbox")
'Set the variable to the Deleted Folder
olkFolderItemsNJ = Application.Session.Folders("ROCNJ").Folders("Deleted Items")
'Set the items, to the items in the Inbox
olkItemsNJ = Application.Session.Folders("ROCNJ").Folders("Inbox").Items
'Set the variable to the Inbox Folder
olkFolderOld = Application.Session.Folders("ROCLI@xxxx.com").Folders("Inbox")
'Set the variable to the Deleted Folder
olkFolderItemsOld = Application.Session.Folders("ROCLI@xxxx.com").Folders("Deleted Items")
'Set the items, to the items in the Inbox
olkItemsOld = Application.Session.Folders("ROCLI@xxxx.com").Folders("Inbox").Items
End Sub
'Function that is the handler which is fired before any item is moved
Private Sub olkFolder_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As MAPIFolder, ByRef Cancel As Boolean) Handles olkFolder.BeforeItemMove, olkFolderCT.BeforeItemMove, olkFolderNJ.BeforeItemMove, olkFolderOld.BeforeItemMove
'If the item is moved to any folder Add the HTML to the email
If MoveTo.Name Is Nothing Then
'Update the body of the item (Email)
Item.HTMLBody = "<HTML><BODY><font size=4 color=red><b>Email Handled By " & System.Environment.UserName & " At " & Now() & "</b></font><BR><BR>" & Item.HTMLBody & "</body></html>"
'Save the email, or else nothing will be changed on the server
Item.Save
'If its moved to any folder with a name (Failsafe)
Else
'Same as above
Item.HTMLBody = "<HTML><BODY><font size=4 color=red><b>Email Handled By " & System.Environment.UserName & " At " & Now() & "</b></font><BR><BR>" & Item.HTMLBody & "</body></html>"
'Same as above
Item.Save
End If
Dim UserName, DeletedTime, ReceiveTime, Subject, Body, SentFrom, SentTo As String
UserName = Environment.UserName
DeletedTime = Now()
ReceiveTime = Item.ReceivedTime
Subject = Item.Subject
Body = Item.HTMLBody
SentFrom = Item.SenderName
SentTo = Item.To
End Sub
End Class
答案 0 :(得分:0)
最有可能发生的事情是加载项崩溃,因为您在BeforeItemMove事件中没有错误处理。如果用户永久删除电子邮件,则MoveTo文件夹可以为null,并且当您尝试评估MoveTo.Name时,代码将失败并且加载项将崩溃。只需处理它并将所有内容包装在Try / Catch块中并相应地处理异常。