Page 1 of 1
Usando gmail
Posted: Tue May 14, 2013 9:37 am
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
Re: Usando gmail
Posted: Tue May 14, 2013 9:57 am
by Antonio Linares
Re: Usando gmail
Posted: Tue May 14, 2013 11:33 am
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
Re: Usando gmail
Posted: Tue May 14, 2013 11:41 am
by Antonio Linares
Screenshot:
Re: Usando gmail
Posted: Tue May 14, 2013 12:11 pm
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.
Re: Usando gmail
Posted: Tue May 14, 2013 12:53 pm
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.
Re: Usando gmail
Posted: Tue May 14, 2013 1:48 pm
by AngelSalom
Bravo Antonio, buen trabajo.
Re: Usando gmail
Posted: Wed May 15, 2013 2:26 pm
by Antonio Linares
Re: Usando gmail
Posted: Mon May 27, 2013 5:35 pm
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