我的VB.NET应用程序旨在与Outlook并行工作以执行以下操作。VB.NET - Microsoft.Office.Interop.Outlook - 在工作站被锁定时不起作用?
- 检查新的未读电子邮件,每10秒(定时器),从每场
- 捕获数据(收件人,发件人,日期,主题,正文等),并存储在SQL表中,
- 从收件箱中删除电子邮件。
此应用程序完美地工作,直到工作站从屏幕保护程序超时时间锁定自己的时刻。当PC解锁后,它恢复正常操作并处理积压的电子邮件。你可能会说只是禁用屏幕保护程序,但这台PC只能通过微软Remote Desktop Connection使用共享用户帐户访问,所以这是不可能的。
这在Windows XP SP3和Outlook 2003下运行。我的问题不是真的找到解决方案,它更多的是找到原因。但显然一个解决方案会很好。
下面是从应用程序代码片段,它的基本Microsoft.Office.Interop.Outlook VB.NET代码:
Public Sub Outlook_GetMail()
Dim sFileName As String = "senderexcludedlist.txt"
Dim ssenderexcludedlist As String = ""
If System.IO.File.Exists(sFileName) = True Then
Dim objReader As New System.IO.StreamReader(sFileName)
Do While objReader.Peek() <> -1
ssenderexcludedlist = objReader.ReadLine()
Loop
objReader.Dispose()
End If
Dim sMessage As String = ""
' Create Outlook application.
Dim oApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application
' Get Mapi NameSpace.
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("Mailbox", Missing.Value, False, True)
' Get Messages collection of Inbox.
Dim oInbox As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
Dim oItems As Microsoft.Office.Interop.Outlook.Items = oInbox.Items
' Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true")
' Loop each unread message.
Dim oMsg As Microsoft.Office.Interop.Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
On Error Resume Next
oMsg = oItems.Item(i)
Dim strBody = oMsg.Body()
strBody = Replace(strBody, vbNewLine, "<BR>")
strBody = Replace(strBody, "'", "´")
Dim strSenderEmailAddress As String = oMsg.SenderEmailAddress
If InStr(ssenderexcludedlist, strSenderEmailAddress) = 0 And Not oMsg.SenderName.Contains("Leeds Tech Support") Then
sMessage = sMessage & oMsg.Subject & vbNewLine
sMessage = sMessage & oMsg.SenderName & vbNewLine
sMessage = sMessage & strSenderEmailAddress & vbNewLine
sMessage = sMessage & oMsg.CC & vbNewLine
sMessage = sMessage & oMsg.ReceivedTime & vbNewLine
sMessage = sMessage & oMsg.Body & vbNewLine
sMessage = sMessage & "---------------------------" & vbNewLine & vbNewLine
MsgLog.Text = sMessage & MsgLog.Text
'INSERT SQL HERE
End If
oMsg.UnRead = False
oMsg.Delete()
Next
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing
End Sub
我想它与工作站锁定时从交换服务器断开连接有关。你记录错误/例外吗?如果是这样,当工作站锁定时会发生什么?另外,请检查Windows事件日志。 –