Article ID: | qGEN017 |
Date Revised: | May 11, 1999 |
Keywords: | mailto, E-Mail, ShellExecute |
See Also: | qGEN015 qGEN010 Download spyin.zip to get the dfWinAPI classlib |
Question: How can mailto: be used to send E-Mail from VFP?
Answer: You can use the ShellExecute API call (or the _ShellExecute class in VFP6) to launch the mailto: target from inside VFP. This UDF wraps the call and allows other parts of the E-Mail to be sent as arguments.
* mailto.prg 06-28-98
* this function initiates the default email client
* 29-Jun-98 added clauses based on KB article about IE4
lparameters pcRecipient, pcSubject, pcBody, pcCC, pcBCC
local oShell, lcRecipient, lcSubject, lcBody, lcCC, lcBCC, lnRetVal
if ( type( "pcRecipient" ) != "C" )
lcRecipient = ""
else
lcRecipient = alltrim( pcRecipient )
endif
if ( type( "pcSubject" ) != "C" )
lcSubject = ""
else
lcSubject = "?subject=" + pcSubject
endif
if ( type( "pcBody" ) != "C" )
lcBody = ""
else
lcBody = "&body=" + strtran( alltrim( pcBody ), chr(13), "%0d" )
lcBody = strtran( lcBody, chr(10), "%0a" )
endif
if ( type( "pcCC" ) != "C" )
lcCC = ""
else
lcCC = "&cc=" + alltrim( pcCC )
endif
if ( type( "pcBCC" ) != "C" )
lcBCC = ""
else
lcBCC = "&bcc=" + alltrim( pcBCC )
endif
set classlib to dfwinapi additive
oShell = createobject( "ShellExecute" )
with oShell
.mcDocApp = "mailto:" + lcRecipient + lcSubject + lcCC + lcBCC + lcBody
lnRetVal = .Execute()
endwith
return ( lnRetVal = 0 )