Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script that save attachment automatically

Status
Not open for further replies.

jjaanus

IS-IT--Management
Dec 12, 2003
9
EE
hi

does anyone knows or have an example script how to save automatically email attachment to harddrive from specific sender when it arrives.

Jaanus
 
look at this, it uses the Current Session of Outlook:
Dim olObj
Set olObj = CreateObject("Outlook.Application")
Set MyNameSpace = olObj.getNameSpace("MAPI").getDefaultFolder(6)
Set myInboxItems = myNameSpace.Items
For i = 1 To 1
Set InbxItms = myInboxItems(i)
With InbxItms
WScript.Echo(i&vbTab&"UNREAD STATUS : " &.unread)
WScript.Echo(vbTab&"DATE : "&.CreationTime)
WScript.Echo(vbTab&"FROM : "&.sendername)
WScript.Echo(vbTab&"TO : "&.to)
WScript.Echo(vbTab&"SUBJECT : "&.subject)
If .attachments.count = 0 Then
WScript.Echo(vbTab&"ATTACHMENTS : NONE")
else
For p = 1 To .attachments.count
WScript.Echo(vbTab&"ATTACHMENT : " &.attachments(p))
.SaveAs "c:\temp\"&.attachments(p)
Next
end If
.close(i)
End With
WScript.Echo("-------------------------------------------------------------")
next

Set myItem = nothing
Set myItems = nothing
Set myInbox = nothing
Set MyNameSpace = Nothing
Set olObj = Nothing
 
..when i copy this code to VisualBasic,it wount recognize command "WScript".
what should i do? how i run this script?


Jaanus
 
the wscript.echo just puts output to the screen. if you do not care about seeing the output then you can delete the wscript lines.

so try this:
Dim olObj
Set olObj = CreateObject("Outlook.Application")
Set MyNameSpace = olObj.getNameSpace("MAPI").getDefaultFolder(6)
Set myInboxItems = myNameSpace.Items
For i = 1 To 1
Set InbxItms = myInboxItems(i)
With InbxItms
If .attachments.count = 0 Then
WScript.Echo(vbTab&"ATTACHMENTS : NONE")
else
For p = 1 To .attachments.count
.SaveAs "c:\temp\"&.attachments(p)
Next
end If
.close(i)
End With
next
Set myItem = nothing
Set myItems = nothing
Set myInbox = nothing
Set MyNameSpace = Nothing
Set olObj = Nothing


I should also mention that i = 1 To 1 will only look at the first message in the outlook inbox. You will need at adjust this to go through all the messages in the inbox. You can try i = 1 to myInboxItems.count. I have not tested though. Hope this helps
 
now it works
tnx

but now is the same popup window that appears in my second tread (script that sends email w attachment automatically)

about security.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top