Usando gmail

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Usando gmail

Post by Antonio Linares »

Code: Select all

#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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Usando gmail

Post by Antonio Linares »

Funcionando! :-)

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

Code: Select all

#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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Usando gmail

Post by Antonio Linares »

Screenshot:

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
hmpaquito
Posts: 1200
Joined: Thu Oct 30, 2008 2:37 pm

Re: Usando gmail

Post by hmpaquito »

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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Usando gmail

Post by Antonio Linares »

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
User avatar
AngelSalom
Posts: 664
Joined: Fri Oct 07, 2005 7:38 am
Location: Vinaros (Castellón ) - España
Contact:

Re: Usando gmail

Post by AngelSalom »

Bravo Antonio, buen trabajo.
Angel Salom
http://www.visionwin.com
---------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.0
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Usando gmail

Post by Antonio Linares »

regards, saludos

Antonio Linares
www.fivetechsoft.com
ltorres
Posts: 42
Joined: Mon Jan 17, 2011 3:44 pm
Location: Lima - Peru

Re: Usando gmail

Post by ltorres »

Esta me funcionó para envío de correo !!!!

Gracias

Antonio Linares wrote:

Code: Select all

#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
Post Reply