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

Retrieving the actual attachments not Outlook item.

Status
Not open for further replies.

dennis22

Programmer
Oct 8, 2002
32

Hi to all!

I have retrieved information from emails received from our clients (infos such as body, attachments etc.). Works well using outlook automation, until I encountered saving an attachment that is an Outlook Item (sample.msg). How do I get the body and attachment from inside that sample.msg file.

Thanks!

Dennis :)



 
Here is an example on how to retreive an attachment.
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(olFolderInbox).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

You will other useful bits of code in faq184-3894.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for your reply sir Mike! :)

I was able to do that using the code you provided in the faq and it does the job. However, I received a message from our client with an Outlook item attachment, it has a ".msg" extension and the file description says it was an Outlook Item. When I look at the Outlook Inbox folder the icon of the attachment was an envelope icon, I was expecting a pdf or doc icon. When I open that file that was saved Outlook opens and there it was, the doc file attachment I've been wanting to save.

I was wondering you guys might have a fix on how to do that.

Thanks again! :)
Dennis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top