Usando gmail

Usando gmail

Postby Antonio Linares » Tue May 14, 2013 9:37 am

Code: Select all  Expand view
#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: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Re: Usando gmail

Postby Antonio Linares » 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: Select all  Expand view
#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: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Usando gmail

Postby Antonio Linares » Tue May 14, 2013 11:41 am

Screenshot:

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Usando gmail

Postby hmpaquito » 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.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Usando gmail

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

Re: Usando gmail

Postby AngelSalom » Tue May 14, 2013 1:48 pm

Bravo Antonio, buen trabajo.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Usando gmail

Postby Antonio Linares » Wed May 15, 2013 2:26 pm

Enviar un email con gmail:

viewtopic.php?p=111825#p111825
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41366
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Usando gmail

Postby ltorres » Mon May 27, 2013 5:35 pm

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

Gracias


Antonio Linares wrote:
Code: Select all  Expand view
#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
ltorres
 
Posts: 42
Joined: Mon Jan 17, 2011 3:44 pm
Location: Lima - Peru


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests