CDOSYS sends the email directly to the SMTP server you designate. Thus, it can come in handy when avoiding the Outlook security alert you may have noticed in my previous blog entries Email and VFP: Part 1a and Part 1b. Special Note: CDOSYS (A.K.A CDO 2.0) first came out with the Windows 2000 OS.
********************************!* Example of using SendViaCDOSYS*******************************DIMENSION aryAttach(2)aryAttach(1) = "C:\attachment1.txt" && change to an actual file that exists on your computeraryAttach(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 formatllHTMLFormat = .T. && change to .F. to send plain text messagelcBody = "<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 ServerlcUserName = "me@myhost.com" && my SMTP usernamelcPassword = "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 ENDTRYENDPROC
UPDATES07-12-2005 Changed the title of this entry so it matched the previous ones and fixed lcBody assignment that got butchered when I changed to html mode before posting the entry, fixed attachment names, changed title so subject matter could be easily discerned
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u