我有一个vbscript,用于查看收件箱中未读的电子邮件,并将附件保存在文件夹中。如果我手动点击它,但是当我从SQL Server 2005运行它时挂起,这个脚本就可以工作了。有些人可以告诉我它有什么问题吗?
这是脚本:
Const olFolderInbox = 6
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objMailbox = objNamespace.Folders("mailbox - ABC")
Set objFolder = objMailbox.Folders("Inbox")
Set colItems = objFolder.Items
Set colFilteredItems = colItems.Restrict("[UnRead] = True")
For Each objMessage in colFilteredItems
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile "C:\" & _
objMessage.Attachments.Item(i).FileName
Next
End If
objMessage.Unread = False
Next
这是我在SQL中用来运行脚本的内容:
DECLARE @SQLCommand VARCHAR(400)
SET @SQLCommand = 'cscript C:\Outlook.vbs'
EXEC master..xp_cmdshell @SQLCommand