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

outlook automation 1

Status
Not open for further replies.

junkmail

Programmer
Jan 7, 2001
134
US
I know you can automate outlook with foxpro but can you automate the process of clicking on the link to a file and do a "saveas" to a specific path on the computer. The link is contained in the body of the email. I get files as links and not attachments and I want to automate the process of downloading the files.

Thanks
Frank
 
junkmail,

This is not completely automatic and requires a little user intervention to decide where to save the files, but it should give you some ideas (cut-n-paste the code below and run it from within VFP) Note: this will only look at unread messages containing links to files you will need to modify to suit.
Code:
*!* Credit goes to mgagnon and his FAQ:
*!* Useful functions with Outlook Automation   faq184-3894
*!* for the first part of this code automating Outlook
Local oOutlookObject,olNameSpace
#Define olFolderInBox 6
oOutlookObject = Createobject("Outlook.Application")
olNameSpace = oOutlookObject.GetNameSpace("MAPI")
oItems= olNameSpace.GetDefaultFolder(olFolderInBox).Items
For Each loItem In oItems
    If loItem.unRead 
		GetFilesFromEmail(loitem.htmlbody) && or use body which contains HYPERLINK "
    Endif
NEXT

FUNCTION GetFilesFromEmail(tcBody)
	LOCAL lnCounter, lnAt, lcLink, lcPart
	FOR lnCounter = 1 TO 1000 && there probably will never be 1000 links
		lnAt = AT([<a href="],tcBody,lnCounter) + 9
		IF lnAt > 9
			lcPart = SUBSTR(tcBody,lnAt)
			lcLink = LEFT(lcPart,AT(["],lcPart,1) - 1)
			GetFileFromWeb(lcLink)  &&If you want it automated further then you will need to use InternetReadFile and InternetOpenUrl among others
		ELSE
			EXIT
		ENDIF
	ENDFOR
ENDFUNC

PROCEDURE GetFileFromWeb(tcLink)
Local tcLink, nRet

Declare DoFileDownload IN shdocvw.dll STRING lpszFile 

tcLink = HandleUnsafeChars(tcLink)

IF !EMPTY(tcLink)
    nRet=DoFileDownload(STRCONV(tcLink,5))
ELSE
    MESSAGEBOX("Function returned an empty length string.",16,"Something is Wrong")
ENDIF
ENDPROC


************************
FUNCTION HandleUnsafeChars(sAddressUrl)
***Purpose: Change unsafe chars to escape sequences
************************
    #DEFINE ICU_BROWSER_MODE 33554432 && 0x2000000 

    DECLARE INTEGER InternetCanonicalizeUrl IN wininet; 
        STRING sURL, STRING @sBUFFER, INTEGER @nLength, INTEGER nFlags 

    LOCAL sNewUrl, nResult 

    nResult = 250 
    sNewUrl = Replicate(Chr(0), nResult) 

    IF InternetCanonicalizeUrl (sAddressUrl,@sNewUrl, @nResult, ICU_BROWSER_MODE) <> 0 
        RETURN Left(sNewUrl, nResult)
    ELSE
        RETURN ""
    ENDIF 
    
ENDFUNC &&HandleUnsafeChars

boyd.gif

craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Craig

Congrats! You've come a long way with this stuff.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks for the help but if I can trouble someone to help me with a snippet of code that would allow me to save the file without any user intervention that would be great. Thanks in advance.

Frank
 
Craig pointed out, and I also would suggest, that you should look at Mike's FAQ.

Useful functions with Outlook Automation
faq184-3894

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top