# Friday, July 15, 2005

As we saw in the last example, ShellExecute comes with a pretty serious size restriction for the MailTo URL - 2048 bytes (though it was 2020 bytes on my system).  That's just not large enough for the contents of most emails.  If your users use Outlook Express, then the following code may come in handy.  It raises the restriction from about 2KB to almost 32KB.

*******************************
*!* Example of using SendViaWinExec
*******************************
LOCAL lcTo, lcSubject, lcBody, lcCC, lcBCC, lcErrReturn
lcTo = "
someone@somewhere.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@boss.com"

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

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

*******************************************
PROCEDURE SendViaWinExec(tcReturn, tcTo, tcSubject, tcBody, tcCC, tcBCC)
*******************************************

DECLARE INTEGER WinExec IN kernel32 ;
    STRING lpCmdLine ,;
    INTEGER uCmdShow

  LOCAL lcCommand, lcCRLF
 
  TRY
    lcCRLF = "%0D%0A"
    lcCommand = ["C:\Program Files\Outlook Express\msimn.exe" /mailurl: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) > 32766 && should be 32768, but not on my system
      THROW "Mailto command is limited to 32768 bytes"
    ENDIF

 WinExec(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 "WinExec"
  ENDTRY
ENDPROC

UPDATES
07/15/2005 Changed the THROW so it reflected 32768 bytes instead of 2048 bytes

Friday, July 15, 2005 1:23:35 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]

 

Archive

<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789