Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: M. Akram Bhatti
  Where is M. Akram Bhatti?
 Riyadh
 Saudi Arabia
 M. Akram Bhatti
 To: Ahsan Rana
  Where is Ahsan Rana?
 Lahore
 Pakistan
 Ahsan Rana
 Tags
Subject: RE: CDO Configuration
Thread ID: 249156 Message ID: 249183 # Views: 13 # Ratings: 1
Version: Visual FoxPro 7 Category: Other
Date: Wednesday, December 30, 2009 7:26:42 AM         
   


> Hi Expert
>
> Following is the Code I use to Configure CDO Messaging but it does not configure. Can any one help me to Configure it. Afterward I try with Outlook Express. Now system successfully sending mail but it takes about one minute for each mail. My Mail sending code is also hereunder:
>
> LOCAL loConfig AS CDO.Configuration, loFlds AS Object, loMsg AS CDO.Message
>
> loConfig = CREATEOBJECT("CDO.Configuration")
> loFlds = loConfig.Fields
>
> WITH loFlds
> *- Set the CDOSYS configuration fields to use port 25 on the SMTP server.
> .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
>
> *- Enter name or IP address of remote SMTP server.
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 && 467
>
> *- Assign timeout in seconds
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = .t. && .f.
> .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "ahsanrana59@gmail.com"
> .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="abc"
> *!* .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
> *!* .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="password"
> .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
>
> .Update()
> ENDWITH
>
> **************************************************
>
> DECLARE SHORT InternetGetConnectedState In WinInet.Dll ;
> INTEGER @lpdwFlags, Integer dwReserved
> LOCAL lConnected
> lConnected = .F.
> lpdwFlags = 0
> IF InternetGetConnectedState (@lpdwFlags, 0) = 1
> lConnected = .T.
> ENDIF
>
> IF lConnected = .T.
> oMSG = CREATEOBJECT("CDO.Message")
> oMSG.To = Thisform.txtEmailAdd.Value
> oMSG.From = Thisform.txtSender.Value
> oMSG.Subject = Thisform.txtSubject.Value
> oMSG.TextBody = ALLTRIM(Thisform.Edit1.Value)
> IF !EMPTY(Thisform.txtAttachment.Value)
> oMsg.AddAttachment(Thisform.txtAttachment.Value)
> ENDIF
> oMSG.Send()
> WAIT WINDOW 'Message to '+ALLTRIM(nm)+' successfully delivered' NOWAIT
> ENDIF
>
> Rgds:
> Ahsan Rana

You can try Blat262 also to send emails. This examples has been taken from:
http://www.sweetpotatosoftware.com/SPSBlog/default.aspx

*******************************
*!* Example of using SendViaBLAT
*******************************
#DEFINE PRIORITYHIGH 1
#DEFINE PRIORITYLOW 0

DIMENSION aryAttach(1)
aryAttach(1) = "C:\attachment1.txt" && change to an actual file that exists on your computer
*aryAttach(2) = "C:\attachment1.zip" && change to an actual file that exists on your computer

LOCAL lcFrom, lcTo, lcSubject, lcBody, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, lnPort, lnPriority, llHTMLFormat, lcErrReturn

lcFrom = "YourID@gmail.com"
lcTo = "rahsan@brain.net.pk"
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 = ""
lcBCC = ""
lcMailServer = "smtp.gmail.com" && my SMTP Server
lnPort = 25 && default SMTP Server port
lcUserName = "YourID@gmail.com" && my SMTP username (Gmail ID)
lcPassword = "yourpassword" && my SMTP password (Gmail)
lnPriority = PRIORITYHIGH

SendViaBLAT(@lcErrReturn, lcFrom, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcMailServer, lnPort, lcUserName, lcPassword, lnPriority, llHTMLFormat)

IF EMPTY(lcErrReturn)
 MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via BLAT")
ELSE
 MESSAGEBOX("'" + lcSubject + "' failed to be sent.  Reason:" + CHR(13) + lcErrReturn, 64, "Send email via BLAT")
ENDIF

*******************************************
PROCEDURE SendViaBLAT(tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tnPort, tcUserName, tcPassword, tnPriority, tlHTMLFormat)
*******************************************
 LOCAL lcBlatParam, lcBodyFile, lnCountAttachments, lnResult, loError as Exception
 
 lcBodyFile = ""
 
 TRY
  *!* Include full path in Declare, such as "C:\Blat240\full\blat.dll"
  *!* or make sure that blat.dll is included in the system's PATH variable
  DECLARE INTEGER Send IN "C:\MyWork_SFH\Development\EMAIL\blat.dll" STRING cParam
  
  lcBodyFile = "C:\MyWork_SFH\Development\EMAIL\Body.txt" &&ADDBS(SYS(2023)) + SYS(2015) + ".txt"
  STRTOFILE(tcBody, lcBodyFile, 0) && body is placed in a text file to be sent by BLAT
  
  lcBlatParam = GetShortPath(lcBodyFile)
  
  IF TYPE("tcTo") = "C"
    lcBlatParam = lcBlatParam + " -to " + ALLTRIM(tcTo)
  ENDIF
  IF TYPE("tcFrom") = "C"
    lcBlatParam = lcBlatParam + " -f " + ALLTRIM(tcFrom)
  ENDIF
  IF TYPE("tcCC") = "C"
    lcBlatParam = lcBlatParam + " -cc " + ALLTRIM(tcCC)
  ENDIF
  IF TYPE("tcBCC") = "C"
    lcBlatParam = lcBlatParam + " -bcc " + ALLTRIM(tcBCC)
  ENDIF
  IF TYPE("tcSubject") = "C"
    lcBlatParam = lcBlatParam + [ -s "] + ALLTRIM(tcSubject) + ["]
  ENDIF
  IF TYPE("tcMailserver") = "C"
    lcBlatParam = lcBlatParam + " -server " + ALLTRIM(tcMailserver)
  ENDIF
  IF TYPE("tnPort") = "N"
    lcBlatParam = lcBlatParam + ":" + TRANSFORM(tnPort)
  ENDIF
  IF TYPE("tcUsername") = "C"
    lcBlatParam = lcBlatParam + " -u " + ALLTRIM(tcUsername)
  ENDIF
  IF TYPE("tcPassword") = "C"
    lcBlatParam = lcBlatParam + " -pw " + ALLTRIM(tcPassword)
  ENDIF
  IF TYPE("tnPriority") = "N" AND BETWEEN(tnPriority, 0, 1)
    lcBlatParam = lcBlatParam + " -priority " + TRANSFORM(tnPriority)
  ENDIF
  IF TYPE("tlHTMLFormat") = "L" AND tlHTMLFormat
    lcBlatParam = lcBlatParam + " -html"
  ENDIF
  
  IF TYPE("taFiles") = "A" && TYPE("taFiles", 1) = "A"
    lcBlatParam = lcBlatParam + " -attach "
   FOR lnCountAttachments = 1 TO ALEN(taFiles)
     lcBlatParam = lcBlatParam + GetShortPath(ALLTRIM(taFiles(lnCountAttachments))) + ","
   ENDFOR
   lcBlatParam = LEFT(lcBlatParam, LEN(lcBlatParam) - 1) && Remove Extra Comma
  ENDIF
MESSAGEBOX(lcBlatParam)
  lnResult = Send(ALLTRIM(lcBlatParam))
  
  IF lnResult != 0
   DO CASE
    CASE lnResult = -2
     THROW "The server actively denied our connection./The mail server doesn't like the sender name. "
    CASE lnResult = -1
     THROW "Unable to open SMTP socket" OR ;
       "SMTP get line did not return 220" OR ;
       "command unable to write to socket" OR ;
       "Server does not like To: address" OR ;
       "Mail server error accepting message data."
    CASE lnResult = 1
     THROW "File name (message text) not given" OR ;
       "Bad argument given"
    CASE lnResult = 2
     THROW "File (message text) does not exist"
    CASE lnResult = 3
     THROW "Error reading the file (message text) or attached file"
    CASE lnResult = 4
     THROW "File (message text) not of type FILE_TYPE_DISK "
    CASE lnResult = 5
     THROW "Error Reading File (message text)"
    CASE lnResult = 12
     THROW "-server or -f options not specified and not found in registry"
    CASE lnResult = 13
     THROW "Error opening temporary file in temp directory"
    OTHERWISE
     THROW "Unknown Error"
   ENDCASE
  ENDIF

 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
  CLEAR DLLS "Send"
  IF FILE(lcBodyFile)
   ERASE (lcBodyFile)
  ENDIF
 ENDTRY
ENDPROC

****************************************
Function GetShortPath
****************************************
 LPARAMETERS lcFileName
 LOCAL lnReturn, lcBuffer

 Declare Integer GetShortPathNameA In Win32API As GetShortPathName String, String, Integer

 lcBuffer = SPACE(255)
 lnReturn= GetShortPathName(lcFileName, @lcBuffer, 255)

 Clear Dlls "GetShortPathName"
 
 Return (Left(lcBuffer, lnReturn))
ENDFUNC


Regards,
akram

ENTIRE THREAD

CDO Configuration Posted by Ahsan Rana @ 12/29/2009 4:41:10 PM
RE: CDO Configuration Posted by Mike Gagnon @ 12/29/2009 5:46:32 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/30/2009 5:19:21 AM
RE: CDO Configuration Posted by Mike Gagnon @ 12/30/2009 12:31:25 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/30/2009 4:22:24 PM
RE: CDO Configuration Posted by Don Higgins @ 12/29/2009 11:50:32 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/30/2009 5:13:35 AM
RE: CDO Configuration Posted by M. Akram Bhatti @ 12/30/2009 7:26:42 AM
RE: CDO Configuration Posted by Ahsan Rana @ 12/30/2009 4:34:00 PM
RE: CDO Configuration Posted by M. Akram Bhatti @ 12/30/2009 6:02:06 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/30/2009 6:40:41 PM
RE: CDO Configuration Posted by Mike Gagnon @ 12/30/2009 11:10:02 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/31/2009 4:11:44 AM
RE: CDO Configuration Posted by Mike Gagnon @ 12/31/2009 12:39:07 PM
RE: CDO Configuration Posted by Ahsan Rana @ 12/31/2009 7:12:30 PM
RE: CDO Configuration Posted by Mike Gagnon @ 1/1/2010 1:17:44 PM
RE: CDO Configuration Posted by Ahsan Rana @ 1/3/2010 6:20:24 AM
RE: CDO Configuration Posted by Mike Gagnon @ 1/3/2010 6:26:42 AM
RE: CDO Configuration Posted by Ahsan Rana @ 1/3/2010 2:26:19 PM
RE: CDO Configuration Posted by Mike Gagnon @ 1/3/2010 5:53:29 PM
RE: CDO Configuration Posted by Ahsan Rana @ 1/3/2010 6:31:31 PM
RE: CDO Configuration Posted by Mike Gagnon @ 1/4/2010 1:56:16 AM
RE: CDO Configuration Posted by Digant Vora @ 12/31/2009 6:54:22 AM
RE: CDO Configuration Posted by Mike Gagnon @ 12/31/2009 12:41:17 PM
RE: CDO Configuration Posted by khubaib khalid @ 1/4/2010 2:40:21 PM
RE: CDO Configuration Posted by Ahsan Rana @ 1/4/2010 4:53:03 PM
RE: CDO Configuration Posted by khubaib khalid @ 1/4/2010 5:03:36 PM