|
******************************* *!* Example of using SendViaCDONTS ******************************* #DEFINE CDOLOW 0 #DEFINE CDONORMAL 1 #DEFINE CDOHIGH 2
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, llHTMLFormat, lcErrReturn
lcFrom = "me@myhost.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"
SendViaCDONTS(@lcErrReturn, lcFrom, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, llHTMLFormat, CDOHIGH)
IF EMPTY(lcErrReturn) MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via CDO NTS") ELSE MESSAGEBOX("'" + lcSubject + "' failed to be sent. Reason:" + CHR(13) + lcErrReturn, 64, "Send email via CDO NTS") ENDIF
******************************************* PROCEDURE SendViaCDONTS(tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tlHTMLFormat, tnImportance) ******************************************* #DEFINE CDOMAILFORMATMIME 0 #DEFINE CDOMAILFORMATTEXT 1
#DEFINE CDOBODYFORMATHTML 0 #DEFINE CDOBODYFORMATTEXT 1
LOCAL loNewMail, lnCountAttachments TRY loNewMail = CREATEOBJECT("CDONTS.NewMail") WITH loNewMail .FROM = tcFrom .TO = tcTo IF TYPE("tcCC") = "C" .CC = tcCC ENDIF IF TYPE("tcBCC") = "C" .BCC = tcBCC ENDIF IF tlHTMLFormat .MailFormat = CDOMAILFORMATMIME .BodyFormat = CDOBODYFORMATHTML ELSE && these are default so not necessary, included for info purposes .MailFormat = CDOMAILFORMATTEXT .BodyFormat = CDOBODYFORMATTEXT ENDIF IF TYPE("tnImportance") = "N" .Importance = tnImportance ELSE .Importance = 1 && Normal ENDIF .Subject = tcSubject .Body = tcBody IF TYPE("taFiles", 1) = "A" FOR lnCountAttachments = 1 TO ALEN(taFiles) .AttachFile = 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 loNewMail loNewMail = .NULL. ENDTRY ENDPROC |