|
******************************* *!* Example of using SendViaCDOSYS ******************************* 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 lcFrom, lcTo, lcSubject, lcBody, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, llHTMLFormat, lcErrReturn
lcFrom = "someone@sommehost.com" lcTo = "someone@sommehost.com" lcSubject = "Hey Have You Tried VFP Email?" *!* Sending the body in HTML format llHTMLFormat = .T. && change to .F. to send plain text message lcBody = "<a href='http://www.sweetpotatosoftware.com/SPSBlog/default.aspx'>" + ; "Hey Have You Tried VFP Email?" + ; "</a>" lcCC = "someoneelse@anotherhost.com" lcBCC = "myboss@bosshost.com" lcMailServer = "mail.myhost.com" && my SMTP Server lcUserName = "me@myhost.com" && my SMTP username lcPassword = "My_PaSsWoRd" && my SMTP password
SendViaCDOSYS(@lcErrReturn, lcFrom, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, llHTMLFormat)
IF EMPTY(lcErrReturn) MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via CDOSYS") ELSE MESSAGEBOX("'" + lcSubject + "' failed to be sent. Reason:" + CHR(13) + lcErrReturn, 64, "Send email via CDOSYS") ENDIF
******************************************* PROCEDURE SendViaCDOSYS(tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tcUserName, tcPassword, tlHTMLFormat) ******************************************* LOCAL lcSchema, loConfig, loMsg, loAtt, lnCountAttachments TRY lcSchema = "http://schemas.microsoft.com/cdo/configuration/"
loConfig = CREATEOBJECT("CDO.Configuration")
WITH loConfig.FIELDS .ITEM(lcSchema + "smtpserverport") = 25 && SMTP Port .ITEM(lcSchema + "sendusing") = 2 && Send it using port .ITEM(lcSchema + "smtpserver") = tcMailServer && host of smtp server .ITEM(lcSchema + "smtpauthenticate") = 1 && Authenticate .ITEM(lcSchema + "sendusername") = tcUserName && Username .ITEM(lcSchema + "sendpassword") = tcPassword && Password .UPDATE ENDWITH
loMsg = CREATEOBJECT ("CDO.Message") loMsg.Configuration = loConfig WITH loMsg .FROM = tcFrom .TO = tcTo IF TYPE("tcCC") = "C" .CC = tcCC ENDIF IF TYPE("tcBCC") = "C" .BCC = tcBCC ENDIF .Subject = tcSubject IF tlHTMLFormat .HTMLBody = tcBody ELSE .TextBody = tcBody ENDIF IF TYPE("tafiles",1) = "A" FOR lnCountAttachments = 1 TO ALEN(taFiles) loAtt=.AddAttachment(taFiles(lnCountAttachments)) ENDFOR ENDIF .SEND() 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 loConfig, loMsg STORE .NULL. TO loConfig, loMsg ENDTRY ENDPROC |