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!

download all attachments in outlook inbox 2

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
319
CA
Hi,

I know I can auto send emails with attachments in vfp (using outlook because I do it all the time) but now I seem to in a situation where I kinda need the reverse..

The situation is as follows:

-I have a supplier who sends me a number of different files per month (it can vary 1 to XX).
-All the files are attachments in .XLS format and are separate emails (so basically I have X number of emails in my INBOX each containing 1 .XLS attachment)

Is there a way in vfp to go in the Outlook INBOX and D/L (or copy) all/each attachment into a specific folder on my Desktop?

Any help at all would be greatly appreciated.


Thanks,
FOXUP!
 
By doing a Search within this forum area for: Inbox I found a number of possible approaches.

Among them I found one that looks like it has a promising approach
Accessing email attachments in Outlook
thread184-419277


Good Luck,
JRB-Bldr

 
Yes, this is possible.

The following code is off the top of my head. It might not be completely right, but it should give you the general idea:

Code:
oOut = CREATEOBJECT("outlook.application")
oNS = oOut.GetNamespace("mapi")
oInbox = oNS.GetDefaultFolder(6) && this is the inbox
FOR EACH oMess IN oInbox.Items
  lcFile = oMess.Attachments(1).FileName
  * lcFile now contains the name of the attached file
ENDFOR

That will give you the name of the attached file. If you can figure out where the attachments are stored, you can then retrieve the file, and do whatever you like with it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Looks like JRB might have given you the answer you need. But just in case you want to follow up myy approach, this is where the attachments appear to be stored on my computer:

Code:
C:\Documents and Settings\<user name>\Local Settings\Temporary Internet Files

That's in Windows XP. For general help in finding the relevant folder, see
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I should have done a "search" first. Thanks. Star to JB & Mike.
 
To use Mike's suggestion of going directly to the Windows directory holding the Attachments you might want to do a Google Search for:
outlook attachment directory default

It might help you Set and/or Find the default directory for the Outlook Attachments.

One challenge with this approach might be if you should happen to have a 'clever' user who, for whatever reasons, sets up their own Outlook Attachment folder different than the 'standard' default you might not be able to find them.
(I only mention this because I do this myself - not that I do it because I consider myself 'clever'.)

Good Luck,
JRB-Bldr
 
Good point, JRB. But the article I referenced shows the registry entries that tell you where the directory in question is located. I assume that, in the case of a "clever" user, they would point to the custom folder rather than the default (you could easily check this for yourself, if you care to).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
One thing to be aware of when using the Outlook attachment directory is that the file names will not necessarily match the attachment file names.

In the case of the same file name being attached to multiple emails, the name in the attachment directory will have " (x)" where x is between 1 and 99 for the (x+1)th copy. BTW, when this number passes 99 on the 101st attachment, Outlook is/was no longer able to save the attachments and you will receive an error opening it. Clearing out your attachment folder will fix/reset this. I don't know if that's been fixed, but it's an issue we saw and worked around.

If you're not aware of this implicit renaming, it can lead to you referencing the first copy of a file multiple times.

When I encountered this, I switched to using the .SaveAsFile method, but prepending the filename with the send date of the email.

So, using the code from FAQ 2838, I would change the initial assignment of the filename as:
Code:
lcFilename = TTOC(loItem.SentOn)+"_"+loItem.attachments.Item(i).filename
 
*Bump*

Hi All,

I seem to have a tiny problem. We recently changed our Email Server from Exchange to Google Cloud. Now, Outlook does not use the "Personal-Inbox" anymore for incoming emails. It (Outlook) uses another folder (also called Inbox in another account which is now in my Outlook). This line: oInbox = oNS.GetDefaultFolder(6) && this is the inbox

is not automatically going to get my attachments anymore because technically they do not reside in Outlook personal inbox. Can anybody help on how to retrieve it from the other "Inbox" ??

Please help.

Thanks,
FOXUP !
 
Sorry for the *BUMP*. I found a work-around. Thanks all.
 
Hi Mike,

I'll post my new code. :) Here it is. I hope that helps. :)

LOCAL lcFilename,lcPath
lcPath="C:\CC\DATA\"

IF !DIRECTORY("C:\CC\DATA\")
MD "C:\CC\DATA\" && Create the directory if it doesn't exist.
ENDIF

oOutLookObject = CREATEOBJECT("Outlook.Application")
olNameSpace = oOutLookObject.GetNameSpace("MAPI")
olFolder="Top Tier Name Here"
myFolder="Inbox"
objFolder1=olNameSpace.Folders(olFolder)
objFolder=objFolder1.Folders(myFolder)
myAtts=objFolder.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)
NEXT
ENDIF
NEXT


Enjoy!!


Thanks,
FOXUP!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top