Monday, April 18, 2011

Code to download attachment from outlook emails

'Below code goes through all the unread mails from inbox folder and download the attachment

'CreateObject method to create an Outlook Application object
Set ObjO=createobject("Outlook.Application")

'GetNameSpece returns a NameSpace object of the specified type
Set olns=ObjO.GetNameSpace("MAPI")

'Get the reference of inbox folder
Set ObjFolder=olns.GetDefaultFolder(6)

'Iterate for all the unread mails and download the attchment from those mails
For each item1 in ObjFolder.Items
If item1.Unread  Then
For each att in item1.attachments
FileName="C:\EmailData\" &att.FileName
att.saveasfile FileName
End If

For more QTP codes, click here.

1 comment:

Please leave your comment here...