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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retrieve attachments from e-mails via Automation

COM and Automation

How to retrieve attachments from e-mails via Automation

by  Mike Gagnon  Posted    (Edited  )
The following code will detect if there are any attachments, in an e-mail and save it to a directory.

Code:
Local lcFilename,lcPath
lcPath="c:\savedattachments\"
If  !Directory("c:\savedAttachments")
	Md "c:\savedAttachments" && Create the directory if it doesn't exist.
Endif
oOutLookObject = Createobject("Outlook.Application")
olNameSpace = oOutLookObject.GetNameSpace("MAPI")
myAtts=olNameSpace.GetDefaultFolder(6).Items
For Each loItem In myAtts
	If loItem.attachments.Count >0 && Make sure there is an actual attachment.
		For i = 1 To loItem.attachments.Count
			lcFilename=""
			lcFilename = loItem.attachments.Item(i).filename
			lcFilename = Alltrim(lcPath)+lcFilename
			loItem.attachments.Item(i).SaveAsFile(lcFilename)
           *loItem.Delete() && The option to delete the message once the attachment has been saved.
		Next
	Endif
Next

Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top