FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Usando gmail
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Usando gmail
Posted: Tue May 14, 2013 09:37 AM
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oMsg  := CreateObject( "CDO.Message" )
   local oConf := CreateObject( "CDO.Configuration" )
   local cSchema := "http://schemas.microsoft.com/cdo/configuration/"
   
   oConf:Fields[ cSchema + "sendusing" ] = 2
   oConf:Fields[ cSchema + "smtpserver" ] = "smtp.gmail.com"
   oConf:Fields[ cSchema + "smtpserverport" ] = 465
   oConf:Fields[ cSchema + "smtpauthenticate" ] = 1
   oConf:Fields[ cSchema + "sendusername" ] = "alinares@fivetechsoft.com"
   oConf:Fields[ cSchema + "sendpassword" ] = "yourpassword"
   oConf:Fields[ cSchema + "smtpusessl" ] = 1
   oConf:Fields:Update()
   
   oMsg:To = "antonio.fivetech@gmail.com"
   oMsg:From ="Antonio <alinares@fivetechsoft.com>" 
   oMsg:Subject = "Test send with gmail account"
   oMsg:HTMLBody = "it works"
   oMsg:Sender = "Antonio"
   oMsg:Organization = "FiveTech"
   oMsg:ReplyTo = "alinares@fivetechsoft.com"
   oMsg:Configuration = oConf
   
   oMsg:Send()
   MsgInfo( "done" )
   
return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Usando gmail
Posted: Tue May 14, 2013 11:33 AM
Funcionando! :-)

Ojo hay que instalar OpenSLL desde aqui:
http://slproweb.com/download/Win32OpenSSL_Light-1_0_1e.exe

Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "c:\harbour\contrib\hbcurl\hbcurl.ch"

#define HB_CURLOPT_RETURNTRANSFER 500

#define OUTFILE  "gmail.xml"

function Main()

   local hCurl, aMatch, cPage, cAction

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mail.google.com/mail/feed/atom" )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_RETURNTRANSFER, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, "antonio.fivetech" + ":" + "yourpassword" )
      curl_easy_setopt( hCurl, HB_CURLOPT_HTTPAUTH, HB_CURLAUTH_BASIC )
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, OUTFILE )
      curl_easy_perform( hCurl )
      curl_easy_reset( hCurl )
   endif

   curl_global_cleanup()

   if File( OUTFILE )
      ParseXML()
   endif   

return nil  

function ParseXML()
   
   local hFile    := FOpen( OUTFILE ) 
   Local oXmlDoc  := TXmlDocument():New( hFile )
   Local oXmlIter := TXmlIterator():New( oXmlDoc:oRoot ), oTagActual
   local aItems   := {}, oEmail

   while .T.
      oTagActual = oXmlIter:Next()
      If oTagActual != nil
         if Upper( AllTrim( oTagActual:cName ) ) == "TITLE"
            if oEmail != nil
               AAdd( aItems, { oEmail:cDate, oEmail:cAuthorName, oEmail:cTitle } )
            endif
            oEmail = TEmail():New()   
            oEmail:cTitle = oTagActual:cData
         endif   

         if Upper( AllTrim( oTagActual:cName ) ) == "ISSUED"
            oEmail:cDate = oTagActual:cData
         endif   

         if Upper( AllTrim( oTagActual:cName ) ) == "AUTHOR"
            oTagActual = oXmlIter:Next()
            oEmail:cAuthorName = oTagActual:cData
            oTagActual = oXmlIter:Next()
            oEmail:cAuthorEmail = oTagActual:cData
         endif   

         // HEval( oTagActual:aAttributes, { | cKey, cValue | MsgInfo( cKey, cValue ) } )
      Else
         Exit
      Endif
   End

   FClose( hFile )

   XBROWSER aItems ;
      SETUP ( oBrw:aCols[ 1 ]:cHeader := "Date",;
              oBrw:aCols[ 2 ]:cHeader := "From",;
              oBrw:aCols[ 3 ]:cHeader := "Title" )

return nil

CLASS TEmail

   DATA  cTitle
   DATA  cDate
   DATA  cAuthorName
   DATA  cAuthorEmail
   
ENDCLASS
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Usando gmail
Posted: Tue May 14, 2013 11:41 AM
Screenshot:

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Usando gmail
Posted: Tue May 14, 2013 12:11 PM

Antonio, eres un genio.
¿ Habría alguna manera de poder descargar los archivos adjuntos a cada email ?

Si se pudiera, quedaría genial: subida y bajada de correos completamente automatizada.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Usando gmail
Posted: Tue May 14, 2013 12:53 PM
Ojo, que no accedemos a todos los emails, sino a los que devuelve:

https://mail.google.com/mail/feed/atom

que son solo los más recientes.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: Usando gmail
Posted: Tue May 14, 2013 01:48 PM

Bravo Antonio, buen trabajo.

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Usando gmail
Posted: Wed May 15, 2013 02:26 PM

Enviar un email con gmail:

viewtopic.php?p=111825#p111825

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 42
Joined: Mon Jan 17, 2011 03:44 PM
Re: Usando gmail
Posted: Mon May 27, 2013 05:35 PM
Esta me funcionó para envío de correo !!!!

Gracias


Antonio Linares wrote:
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oMsg  := CreateObject( "CDO.Message" )
   local oConf := CreateObject( "CDO.Configuration" )
   local cSchema := "http://schemas.microsoft.com/cdo/configuration/"
   
   oConf:Fields[ cSchema + "sendusing" ] = 2
   oConf:Fields[ cSchema + "smtpserver" ] = "smtp.gmail.com"
   oConf:Fields[ cSchema + "smtpserverport" ] = 465
   oConf:Fields[ cSchema + "smtpauthenticate" ] = 1
   oConf:Fields[ cSchema + "sendusername" ] = "alinares@fivetechsoft.com"
   oConf:Fields[ cSchema + "sendpassword" ] = "yourpassword"
   oConf:Fields[ cSchema + "smtpusessl" ] = 1
   oConf:Fields:Update()
   
   oMsg:To = "antonio.fivetech@gmail.com"
   oMsg:From ="Antonio <alinares@fivetechsoft.com>" 
   oMsg:Subject = "Test send with gmail account"
   oMsg:HTMLBody = "it works"
   oMsg:Sender = "Antonio"
   oMsg:Organization = "FiveTech"
   oMsg:ReplyTo = "alinares@fivetechsoft.com"
   oMsg:Configuration = oConf
   
   oMsg:Send()
   MsgInfo( "done" )
   
return nil

Continue the discussion