Page 1 of 1

gmail y OAuth

Posted: Tue Feb 04, 2025 1:30 pm
by horacio
Amigos
Ya no se pueden mandar correos desde gmail en aplicaciones de terceros como lo veníamos haciendo. Ahora hay que usar OAuth. No tengo la menor idea de como configurarlo. Alguien sabe? Gracias de antemano!

Re: gmail y OAuth

Posted: Tue Feb 04, 2025 11:01 pm
by Lailton
Hola Horacio,

Estamos implementando soporte OAuth2 para Gmail y Microsoft (Outlook, Live, Office 365).
El soporte para el envío de correos con OAuth2 estará disponible en la próxima versión de FWH. 😃

Re: gmail y OAuth

Posted: Wed Feb 05, 2025 7:01 pm
by wilsongamboa
si es asi solo por eso compraria la version nueva ja ja ja un abrazo
yo nunca pude usar 365 para envio de mails seria un puntazo !!!
puedes dar algo de contexto como lo van a hacer
curl ? o ?
saludos
Wilson

Re: gmail y OAuth

Posted: Wed Feb 05, 2025 10:15 pm
by Lailton
Si, parte del codigo es con CURL para poder criar los token de comunicacion con los servicos oAuth2.
Cuando listo posto ejemplos con screenshots.

:D

Re: gmail y OAuth

Posted: Thu Feb 06, 2025 2:15 am
by wilsongamboa
gracias estaremos atentos
saludos
Wilson

Re: gmail y OAuth

Posted: Thu Feb 06, 2025 10:36 am
by karinha
Lailton wrote: Wed Feb 05, 2025 10:15 pm Si, parte del codigo es con CURL para poder criar los token de comunicacion con los servicos oAuth2.
Cuando listo posto ejemplos con screenshots.

:D
Lailton, esperando ansioso.

Gracias, tks.

Regards, saludos.

Re: gmail y OAuth

Posted: Thu Feb 06, 2025 12:20 pm
by FiveWiDi
karinha wrote: Thu Feb 06, 2025 10:36 am
Lailton wrote: Wed Feb 05, 2025 10:15 pm Si, parte del codigo es con CURL para poder criar los token de comunicacion con los servicos oAuth2.
Cuando listo posto ejemplos con screenshots.

:D
Lailton, esperando ansioso.

Gracias, tks.

Regards, saludos.
+1

Re: gmail y OAuth

Posted: Sun Feb 09, 2025 7:06 pm
by mauri.menabue
Excellent, we look forward to the next release
TIA :D

Re: gmail y OAuth

Posted: Thu Feb 20, 2025 5:18 pm
by Marco Augusto
Saludos

Si quedó implementado en esta última versión de FWH?

Re: gmail y OAuth

Posted: Mon Feb 24, 2025 5:51 pm
by jose_murugosa
+1

Re: gmail y OAuth

Posted: Mon Feb 24, 2025 6:26 pm
by karinha
Mira,

viewtopic.php?p=277780#p277780

Regards, saludos.

Re: gmail y OAuth

Posted: Tue Feb 25, 2025 6:44 pm
by Lailton
Hola a todos,

Un ejemplo de cómo funciona Harbour + FWH con OAuth.
Image

Aquí tienen un sample del código.
Code Sample

Code: Select all | Expand

#include "fivewin.ch"

static oGmail, hStore

function main()

	local oDlg
	local oName, cName := ""
	local oEmail, cEmail := ""
	local oPhoto, oSend
	local oConnect, oDisconnect

	hStore := readStore( hb_dirBase() + "gmail.json" )

	oGmail := TGmail():new()

	oGmail:setConfig( {;
		"client_id" => "your_client_id",;
		"client_secret" => "your_client_secret",;
		"redirect_uri" => "http://localhost:2025/";
	} )

	if !empty( hStore[ "token" ] )
		oGmail:setToken( hStore[ "token" ] )
	endif

	define dialog oDlg resource "GMAIL"

		redefine image oPhoto id 4002 of oDlg
		redefine say oName var cName id 4003 of oDlg
		redefine say oEmail var cEmail id 4004 of oDlg

		redefine button oDisconnect id 4005 of oDlg action onDisconnect( oDlg, { oPhoto, oName, oEmail, oSend, oDisconnect }, { oConnect } )
		redefine button oSend id 4006 of oDlg action onSendMail()

		redefine button oConnect id 4001 of oDlg action onConnect( oDlg, { oPhoto, oName, oEmail, oSend, oDisconnect }, { oConnect } )

		oDlg:bStart := { || updateControls( oDlg, { oPhoto, oName, oEmail, oSend, oDisconnect }, { oConnect } ) }

		oDlg:lHelpIcon := .f.

	activate dialog oDlg centered

	saveStore( hb_dirBase() + "gmail.json", hStore )

return nil

function onConnect( oDlg, aConnect, aDisconnect )

	local cToken

	if !oGmail:isAuth()
		cToken := oGmail:auth()
		if !empty( cToken )
			hStore[ "token" ] := cToken
		else
			msgStop( "Authentication failed!" )
		endif
	endif

	updateControls( oDlg, aConnect, aDisconnect )

return nil

function onDisconnect( oDlg, aConnect, aDisconnect )

	local cProfile := hb_dirBase() + "profile_gmail.jpg"

	oGmail:revoke()
	updateControls( oDlg, aConnect, aDisconnect )

	if hb_vfExists( cProfile )
		hb_vfErase( cProfile )
	endif

return nil

function onSendMail()

	if oGmail:send( "lailton@paysoft.com.br", "it is a test", "<b>Message from Gmail oAuth2</b>", .t., {} )
		msgInfo( "Mail sent!" )
	else
		msgStop( "Failed to send email. You may not have authorized the required permissions..." )
	endif

return nil

function updateControls( oDlg, aConnect, aDisconnect )

	local hUser
	local cProfile := hb_dirBase() + "profile_gmail.jpg"

	if oGmail:isAuth()
		hUser := oGmail:me()
	endif

	aEval( aConnect, { |o| o:hide() } )
	aEval( aDisconnect, { |o| o:hide() } )

	if hb_isHash( hUser )

		aEval( aConnect, {|o|o:show(),o:refresh()} )

		if !hb_vfExists( cProfile )
			oGmail:downloadUrl( hUser[ "picture" ], cProfile )
		endif

		// Load Profile Photo
		if hb_vfExists( cProfile )
			aConnect[1]:loadImage(, cProfile )
			aConnect[1]:refresh()
		endif

		aConnect[2]:setText( hUser[ "name" ] )
		aConnect[3]:setText( hUser[ "email" ] )

		aConnect[2]:update()
		aConnect[3]:update()

	else

		aEval( aDisconnect, {|o|o:show(),o:refresh()} )

	endif

	oDlg:update()

return nil

function readStore( cFile )

	local hStore

	if hb_vfExists( cFile )
		hStore := hb_jsonDecode( hb_memoRead( cFile ) )
	endif

	if !hb_isHash( hStore )
		hStore := {;
			"token" => "";
		}
	endif

return hStore

function saveStore( cFile, hStore )

	hb_memoWrit( cFile, hb_jsonEncode( hStore ) )

return hb_vfExists( cFile )
Será incluido hoy en FiveWin para la próxima versión :D