servidor smtp de gmail

501 views
Skip to first unread message

Daniel Aisenberg

unread,
Aug 9, 2024, 12:46:55 PM8/9/24
to harbou...@googlegroups.com
Disculpen si ya se respondió esto, no lo encontré..
Al usuar hb_sendmail, estoy recibiendo un issue de autenticación (no así con un servidor por ejemplo de donweb en Argentina.
Hay algún méotodo para usar el servidor smtp de gmail y enviar correo programáticamente?
Gracias!

diego...@gmail.com

unread,
Aug 9, 2024, 2:10:25 PM8/9/24
to Harbour Users
Hola, en el archivo que adjunto tienes una funcion en la cual implemente envio de correo de Gmail utilizando OAuth v2 con curl( puedes usar otra forma ), que seria la que Google esta impulsando a utilizar y dejando las demas opciones discontinuadas. 
Necesitas obtener un access_token de Google por unica vez con el cual podras utilizar este servicio las veces que necesites. 

Hello, in the attached file, you'll find a function that implements sending Gmail using OAuth v2 with curl( you can use another method ), which is the way Google is now encouraging to use while phasing out other options.
You need to obtain an access token from Google just once, which you can then use to access this service whenever you need.  

Diego.
sendGmail.prg

Daniel Aisenberg

unread,
Aug 9, 2024, 2:28:27 PM8/9/24
to harbou...@googlegroups.com
Espectacular! muchas gracias Diego como siempre con muy  buena información.
Saludos


--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/2503c0bb-a97e-40a0-93c7-8c4185c50575n%40googlegroups.com.

GaboMen

unread,
Aug 10, 2024, 12:12:08 AM8/10/24
to harbou...@googlegroups.com

Muchas Gracias.. Diego!!

Precisamente estaba peleandome con eso.. muy agradecido!

lucima...@gmail.com

unread,
Aug 10, 2024, 9:45:24 AM8/10/24
to Harbour Users
Hola diego,
Esta función es muy útil para este nuevo desafío de enviar correos electrónicos a través de Gmail utilizando este nuevo método requerido.
Luego pregunte si habría compilado curl para puerto usando mingw porque aquí no pude generar libcurl.a

Gracias de antemano.

Clippero

unread,
Aug 10, 2024, 10:46:12 AM8/10/24
to Harbour Users
Una consulta:

hb_SendMail( ;
                 _smtp , ;  // SERVER
                _nPort , ;  // PORT
                 _from , ;  // FROM
                   _to , ;  // TO
                   _cc , ;  // CC
                   " " , ;  // BCC
                 _body , ;  // BODY
                 _subj , ;  // SUBJECT
                   Att , ;  // FILES
                 _user , ;  // POP3 USERNAME
                 _pssw , ;  // PASWORD
                  _user, ;  // POP3 USERNAME OR ADDRESS
                     3 , ;  // PRIORITY 1=HIGH  3=NORMAL  5=LOW
                    .F., ;  // READ
  {|| .T.}, ;  // bTRACE o (.T.) para log
                    .F., ;  // AUTHENTICATION
                    NIL, ;  // NO AUTHENTICATION
                    60*1000, ;  // TIMEOUT  ms
                    cReplyTo, ;  // REPLY TO
  IIF(_nPort==465,.T.,.F.) , ;  // TLS
                       , ; // SMTP PASSWORD
                       , ; // CHARSET
                       )

El envío con hb_SendMail() no funciona ?

diego...@gmail.com

unread,
Aug 10, 2024, 10:48:53 AM8/10/24
to Harbour Users

Daniel Aisenberg

unread,
Aug 17, 2024, 11:44:36 PM8/17/24
to harbou...@googlegroups.com

Hola.. Perdón que vuelvo a preguntar sobre este tema. En el código hay una variable cGMAILaccesstoken.

Pregunta:
Ese es el token que descarga de https://console.cloud.google.com/apis/credentials ?
Porque en "My First Project" creé dos id's de clientes Oauth2, uno como "Plataforma universal de windows" y otro como Escritorio" para probarlos..  En ambos casos descargué el archivo json.
Pero al utilizarlo en crudo  no me autentica.
Me devuelve:

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid
authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "errors": [
      {
        "message": "Invalid Credentials",
        "domain": "global",
        "reason": "authError",
        "location": "Authorization",
        "locationType": "header"
      }
    ],
    "status": "UNAUTHENTICATED"
  }
}

Ya creé una pantalla de consentimiento, con un usuario de test (mi gmail).
El proyecto tiene habilitada la api de gmail.
Hay algún otro prerrequisito para que funcione?

Gracias!!




On Fri, Aug 9, 2024 at 3:10 PM diego...@gmail.com <diego...@gmail.com> wrote:

diego...@gmail.com

unread,
Aug 18, 2024, 2:42:52 PM8/18/24
to Harbour Users

Daniel, please here the default language is English.

There are three different things...

  1. Your project credentials (a .json file downloaded from Google Console Dev)
  2. The authorization code (obtained after the Google sign-in screen)
  3. The access token (sent by Google via GET to your redirect_uri)

To use the function I uploaded, you need to have the access token. To do this, first create your project in Google Console Dev, enable the Gmail API, create your consent screen with the correct redirect URI, and also enable permissions there to send Gmail emails (.../auth/gmail.send). Once you have this set up, download the credentials .json file.

Next, you'll need to construct the URL so that Google prompts the user for permission to use the API that you've specified in the URL's scope. For this, you'll need to use a web server. The URL you need to create has this format:


You need to get client_id and redirect_uri from your credentials .json file. When you visit this URL, Google's sign-in page will appear, asking to authorize the services listed in the scope. If the sign-in is successful, Google will redirect via GET to your redirect_uri with the access_token. You only need to perform this step once; once saved, you can use the token as many times as needed for the requested service, in our case, Gmail.

In summary, to obtain an access_token, you'll need to use a web server to handle the request from the URL detailed above. I included an example for mod_harbourV2.1 showing how to obtain an access token to use Google sign-in in a web app. Just add the Gmail scope as detailed above, and you're all set.

Diego

Daniel Aisenberg

unread,
Aug 19, 2024, 2:23:16 PM8/19/24
to harbou...@googlegroups.com
Hola. No sé si alguien pudo implementar la función de acceso a gmail.
Me está devolviendo "Invalid authentication credentials"

    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https:
//developers.google.com/identity/sign-in/web/devconsole-project.",

Estimo que hay algo que estoy mandando mal en el cGMAILaccesstoken..  o bien lo tengo que codificar - porque lo estoy mandando en texto crudo tal como lo descargué de google cloud.

Alguien tiene alguna pista? 
Mil gracias de antemano!




On Fri, Aug 9, 2024 at 3:10 PM diego...@gmail.com <diego...@gmail.com> wrote:

Angel Pais

unread,
Aug 19, 2024, 2:27:19 PM8/19/24
to harbou...@googlegroups.com
Diego acaba de explicarte todo y seguís preguntando lo mismo ?


Daniel Aisenberg

unread,
Aug 19, 2024, 2:48:38 PM8/19/24
to harbou...@googlegroups.com
Sorry, mil disculpas no vi la respuesta anterior

Daniel Aisenberg

unread,
Aug 19, 2024, 2:55:52 PM8/19/24
to harbou...@googlegroups.com
Sorry, I apologize, I didn't see the previous answer.

Angel Pais

unread,
Aug 19, 2024, 2:56:36 PM8/19/24
to harbou...@googlegroups.com
todo bien Daniel
Después contanos si te funcionó.


Clippero

unread,
Aug 20, 2024, 8:57:52 AM8/20/24
to Harbour Users
"Daniel, please here the default language is English."

En esta lista perfectamente se pueden hacer posteos por ejemplo en Español, que el lenguaje predeterminado sea Inglés, es un detalle
En todo caso se podrían poner los comentarios o las consultas en ambos idiomas, sobre todo para poder obtener mejores respuestas de gente que no quiera usar google translator para traducir textos de español a inglés y así entender la pregunta y brindar una respuesta
Reply all
Reply to author
Forward
0 new messages