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

Save Attachment in VFP9 1

Status
Not open for further replies.

Admigha

IS-IT--Management
Aug 22, 2007
21
CA
How Can I Save Attachment w/o openning Outlook Express in VFP9?
knowing that I'm using CDO to send e-mails via FoxPro.
thanks.

Tony Lama
Admigha SoftHouse
 
Hi!,
As far as my knowlegde goes this is not possible with outlook express.
Using Outlook might make sense.
-Bart
 
Tony,

You say you are "opening Outlook Express in VFP 9". How exactly are you doing that?

As far as I know, there's no way to control OE from VFP. At best, you can only launch it and then work with it interactively. Or, you can open a message composing window, with the fields pre-populated with text that you specify. But you cannot access it programmatically in any way.

As Bart say, it's a different story with the full Outlook.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike and Nifrabar,

while you cannot OLE automate Outlook Express it's MAPI compliant and you can use MAPI.Session etc. to control it.

See if you have C:\Program Files\Shared\Microsoft System\MSMAPI\1031 or can create a MAPI.Session object. If you use CDO this should be possible.

Code:
Local lnCount, loMapiSession, loInbox, loMessage, loAttachment

MkDir D:\attachments
lnCount = 0

loMapiSession = CreateObject("MAPI.Session")
loMapiSession.Logon("Outlook") && modify this for your needs

loInbox = loMapiSession.GetDefaultFolder(1) && this too, if you have multiple inbox folders

For Each loMessage IN loInbox.Messages
    If loMessage.Attachments.Count>0
       For Each loAttachment IN loMessage.Attachments
          ? loAttachment.Name
          If InList(loAttachment.Type,1,2)
             loAttachment.WriteToFile("D:\attachments\"+loAttachment.Name)
             lnCount = lnCount + 1
          EndIf
       EndFor 
    EndIf
    * Just a demo, don't save all attachments to disk, that could take a while...
    If lnCount>5 
       Exit    
    EndIf 
EndFor

You could eg check loMessage.Unread and only save attachments of new mails.

Bye, Olaf.
 
Thanks OlafDoschke,
this is exactly what I was looking for,
I tried it and I helped me.
Thanks again.
Tony Lama
Admigha SoftHouse


Tony Lama
Admigha SoftHouse
 
Hi Olaf,
In fact, I was looking for a solution either in Outlook or OE, the solution you gave me is good for outlook, and it didn't work on Outlook express, If I find the solution I will let you know.
Thanks again.

Tony Lama
Admigha SoftHouse
 
Sorry, my code does control the default mail program, as long as it's MAPI compliant, it does not rely on Outlook or Outlook Express. Don't be confused, that I use "Outlook" in my Login call. As the comment says this needs to be modified, it's simply that my mail profile is called Outlook, it is not Oultook specific code.

Simply make the call
loMapiSession.Logon()
without any parameters and you'll get an interactive logon.

Bye, Olaf.
 
Hi Olaf,
As I mensioned, It is working fine on the computer using Outlook, but on the other computer not having outlook it doesn't work, it may need some MAPI components to be installed.

Tony Lama
Admigha SoftHouse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top