|
******************************* *!* Example of using SendViaEsSmtp ******************************* DIMENSION aryAttach(2) aryAttach(1) = "C:\attachment1.txt" && change to an actual file that exists on your computer aryAttach(2) = "C:\attachment2.zip" && change to an actual file that exists on your computer
LOCAL lcFromName, lcFromAddress, lcTo, lcSubject, lcBody, lcCC, lcBCC, lcSMTPServer, lcErrReturn
lcFromName = "My Name" lcFromAddress = "me@myhost.com" lcTo = "someone@theirhost.com" lcSubject = "Hey Have You Tried VFP Email?" lcBody = "Just wanted to let you know that VFP is pretty versatile and has a lot of ways to send email." lcCC = "someoneelse@someotherhost.com" lcBCC = "myboss@bosshost.com" lcSMTPServer = "mail.myhost.com"
SendViaEsSmtp(@lcErrReturn, lcFromName, lcFromAddress, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcSMTPServer)
IF EMPTY(lcErrReturn) MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via EsSmtp") ELSE MESSAGEBOX("'" + lcSubject + "' failed to be sent. Reason:" + CHR(13) + lcErrReturn, 64, "Send email via EsSmtp") ENDIF
******************************************* PROCEDURE SendViaEsSmtp(tcReturn, tcFromName, tcFromAddress, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcSMTPSever) ******************************************* LOCAL loEsSmtp, lnCountAttachments, lnErrorNo TRY loEsSmtp = CREATEOBJECT("ESSMTP.EsSmtpCtrl.1") WITH loEsSmtp IF TYPE("tcSMTPSever") = "C" .SMTPServer = tcSMTPSever ENDIF IF TYPE("tcFromName") = "C" .SourceName = tcFromName ENDIF IF TYPE("tcFromAddress") = "C" .SourceAddress = tcFromAddress ENDIF .DestinationAddress = tcTo IF TYPE("tcCC") = "C" .CCDestinationAddress = tcCC ENDIF IF TYPE("tcBCC") = "C" .BCCDestinationAddress = tcBCC ENDIF .Subject = tcSubject .MailData = tcBody IF TYPE("taFiles", 1) = "A" FOR lnCountAttachments = 1 TO ALEN(taFiles) .AddAttachment(taFiles(lnCountAttachments), 0) && 0 signifies base64 encoding when needed ENDFOR ENDIF IF .SendMail() != 1 && there was a problem lnErrorNo = .ErrorNo DO CASE CASE lnErrorNo = 421 THROW "Service not available, closing transmission channel" CASE lnErrorNo = 450 THROW "Requested mail action not taken: mailbox unavailable [E.g., mailbox busy]" CASE lnErrorNo = 451 THROW "Requested action aborted: local error in processing" CASE lnErrorNo = 452 THROW "Requested action not taken: insufficient system storage" CASE lnErrorNo = 500 THROW "Syntax error, command unrecognized [This may include errors such as command line too long]" CASE lnErrorNo = 501 THROW "Syntax error in parameters or arguments" CASE lnErrorNo = 502 THROW "Command not implemented" CASE lnErrorNo = 503 THROW "Bad sequence of commands" CASE lnErrorNo = 504 THROW "Command parameter not implemented" CASE lnErrorNo = 550 THROW "Requested action not taken: mailbox unavailable [E.g., mailbox not found, no access]" CASE lnErrorNo = 552 THROW "Requested mail action aborted: exceeded storage allocation" CASE lnErrorNo = 553 THROW "Requested action not taken: mailbox name not allowed [E.g., mailbox syntax incorrect]" CASE lnErrorNo = 554 THROW "Transaction failed" OTHERWISE THROW "Unknown Error - Might be WinSock Related" ENDCASE ENDIF ENDWITH
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 RELEASE loEsSmtp loEsSmtp = .NULL. ENDTRY ENDPROC |