Computing Staff
  • 0

VBScript To Save Unread Mail Outlook

  • 0

Hey all,

I have this script but when have added the unread
Section it doesn’t like it ?

When it’s out it works like magic!

Can someone take a look for me ?

And if it’s not too much to ask after the attachment saves
To make it ‘read’ I have a little bit right at the end…

Dim oFSO
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
oFSO.CreateFolder “C:\Temp”


‘START TO EXTRACT FILES

‘below doesn’t seem to work

Dim objMessage As Outlook.MailItem

Const olFolderInbox = 6
Set objOutlook = CreateObject(“Outlook.Application”)
Set objNamespace = objOutlook.GetNamespace(“MAPI”)

Set objFolder = objNameSpace.Folders(“Mailbox – Gmail”).Folders(“folder”).Folders(“Sub1”)        ‘ FIRST FILE HERE
Set colItems = objFolder.Items

For Each objMessage in colItems
If objMessage.UnRead = True Then
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile “C:\Temp\” &  _
objMessage.Attachments.Item(i).FileName
Next i
End If
End If
Next objMessage

Set objFolder = objNameSpace.Folders(“Mailbox – Gmail”).Folders(“folder”).Folders(“Sub2”)        ‘ SECOND FILE HERE
Set colItems = objFolder.Items

For Each objMessage in colItems
If objMessage.UnRead = True Then
intCount = objMessage.Attachments.Count
If intCount > 0 Then
For i = 1 To intCount
objMessage.Attachments.Item(i).SaveAsFile “C:\Temp\” &  _
objMessage.Attachments.Item(i).FileName
Next i
End If
End If
Next objMessage

msgBox “UnRead Attachments Saved!”

‘ maybe use this??

‘ If objUnreadMessage.UnRead = True Then
‘     objUnreadMessage.UnRead = False
‘ End If

Share

2 Answers

  1. Can’t help much, don’t have outlook. If everything works except the “unread section” (i guess you mean: ‘If objMessage.UnRead = True Then’)
    see what happens when you look at this item:
    msgbox objMessage.UnRead
    Also, doesn’t vbscript frown on “NEXT var”? (mine does, it wants: NEXT, without the variable, like):
    for i=1 to 10
    msgbox i
    next
    otherwise i get “line 3: expected end of statement”

    • 0