travelnitwit
Technical User
I have a vbscript that looks at unread emails in an inbox and saves the attachment in a folder. This script works if I click on it manually but hangs when I run it from SQL server 2005. Can some please let me know what could be wrong with it?
Here is the script:
This is what i use in SQL to run the script:
Here is the script:
Code:
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
This is what i use in SQL to run the script:
SQL:
DECLARE @SQLCommand VARCHAR(400)
SET @SQLCommand = 'cscript C:\Outlook.vbs'
EXEC master..xp_cmdshell @SQLCommand