# Friday, July 15, 2005

You can send a Mailto URL as the command to ShellExecute to facilitate email in VFP.  It should be noted that the command line (URL) is limited to 2048 bytes (though on my system I couldn't create one longer than 2020 bytes) and there is no facility for attaching files using this method.  These severe limitations aside, it is a solution that has its places in VFP development.

*******************************
*!* Example of using SendViaShell
*******************************
LOCAL lcTo, lcSubject, lcBody, lcCC, lcBCC, lcErrReturn
lcTo = "
someone@somehost.com"
lcSubject = "Hey Have You Tried VFP Email?"
lcBody = "Just wanted to let you know that VFP is pretty versatile" + CHR(13) + "and has a lot of ways to send email."
lcCC = "
someoneelse@anotherhost.com"
lcBCC = "
myboss@bosshost.com"

SendViaShell(@lcErrReturn, lcTo, lcSubject, lcBody, lcCC, lcBCC)

IF EMPTY(lcErrReturn)
  MESSAGEBOX("'" + lcSubject + "' opened successfullly.", 64, "Send email via Shell")
ELSE
  MESSAGEBOX("'" + lcSubject + "' failed to be sent.  Reason:" + CHR(13) + lcErrReturn, 64, "Send email via Shell")
ENDIF

*******************************************
PROCEDURE SendViaShell(tcReturn, tcTo, tcSubject, tcBody, tcCC, tcBCC)
*******************************************
  DECLARE INTEGER ShellExecute IN shell32.DLL ;
    INTEGER hwndWin, STRING cOperation, STRING cFile, ;
    STRING cParameters, STRING cDirectory, INTEGER nShowWin

  LOCAL lcCommand, lcCRLF
 
  TRY
    lcCRLF = "%0D%0A"
    lcCommand = "mailto:" + tcTo + "?Subject=" + tcSubject + "&Body=" + STRTRAN(tcBody, CHR(13), lcCRLF)
    IF TYPE("tcCC") = "C"
      lcCommand = lcCommand + "&CC=" + tcCC
    ENDIF
    IF TYPE("tcBCC") = "C"
      lcCommand = lcCommand + "&BCC=" + tcBCC
    ENDIF
    IF LEN(lcCommand) > 2020 && should be 2048, but not on my system
      THROW "Mailto command is limited to 2048 bytes"
    ENDIF
    ShellExecute(0, "open", lcCommand, "", "", 1)
  CATCH TO loError
    tcReturn = [Error: ] + STR(loError.ERRORNO) + CHR(13) + ;
      [LineNo: ] + STR(loError.LINENO) + CHR(13) + ;
      [Message: ] + loError.MESSAGE + CHR(13) + ;
      [Procedure: ] + loError.PROCEDURE + CHR(13) + ;
      [Details: ] + loError.DETAILS + CHR(13) + ;
      [StackLevel: ] + STR(loError.STACKLEVEL) + CHR(13) + ;
      [LineContents: ] + loError.LINECONTENTS
  FINALLY
    CLEAR DLLS "ShellExecute"
  ENDTRY
ENDPROC

Friday, July 15, 2005 12:41:11 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]

 

Archive

<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678