# Wednesday, July 13, 2005

CDO NTS (A.K.A. CDO 1.2.1) is another way to send email from VFP.  It is no longer included with newer versions of the Windows OS.  I could speak at length about it, but there is already some goood information out on the MSDN: Introduction to CDO NTS and The NewMail Object

*******************************
*!* 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

Wednesday, July 13, 2005 8:11:58 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

 

Archive

<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789