gmail

Post Reply
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

gmail

Post by Colin Haig »

Hi All

Is it possible to access email and attachments in a gmail account from a fivewin/xHarbour app.

Cheers


Colin
Ariel
Posts: 309
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: gmail

Post by Ariel »

Colin,

I use this for an account of gmail and it works perfectly :

Code: Select all

MsgRun( "Enviando correo, espere...", oApp:EmpresaName, {|| lBorrar := Config_Mail( cUser, cPass, cRemt, cDest, cCC, cCCO,;
                                                                                       cText, cSubject, aTmp, nServ, aServs ) } )


********************************************************************************
Static Function Config_Mail( _cUser, cPass, _cRemt, cDest, cCC, cCCO, cTxt,;
                             cSubject, aAttach, nServ, aServs )

  local lRet := .f.
  local oCfg, oError, cUser, cRemt
  local cServ := aServs[nServ][2]  //--> SERVIDOR SMTP - "smtp.servidor.com.br"
  local nPort := aServs[nServ][3]
  local lAut  := .t.
  local lSSL  := aServs[nServ][4]
  
  
  if Empty(cPass) .or. Empty(_cRemt) .or.;
    ( Empty(cDest) .and. Empty( cCC ) .and. Empty(cCCO) )
     Msgstop( "Error en configuracion de la cuenta.", "Atencion" )
     return .f.
  else
     cUser := alltrim(_cUser) + aServs[nServ,1]
     cRemt := alltrim(_cRemt) + aServs[nServ,1]
  endif   

  TRY
    oCfg := CREATEOBJECT( "CDO.Configuration" )
      WITH OBJECT oCfg:Fields
           :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"       ):Value := cServ
           :Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport"   ):Value := nPort
           :Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"        ):Value := 2
           :Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := lAut
           :Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl"       ):Value := lSSL
           :Item( "http://schemas.microsoft.com/cdo/configuration/sendusername"     ):Value := cUser
           :Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword"     ):Value := cPass
           :Update()
      END WITH
      lRet := .t.
  CATCH oError
    MsgInfo( "No fue posible enviar el e-Mail!"  +CRLF+ ;
             "Error: "     + Transform(oError:GenCode,   nil) + ";" +CRLF+ ;
             "SubC: "      + Transform(oError:SubCode,   nil) + ";" +CRLF+ ;
             "OSCode: "    + Transform(oError:OsCode,    nil) + ";" +CRLF+ ;
             "SubSystem: " + Transform(oError:SubSystem, nil) + ";" +CRLF+ ;
             "Mensaje: "   + oError:Description, "Atencion!" )

  END
  if lRet
     lRet := Envia_Mail( oCfg, cRemt, cDest, cCC, cCCO, cTxt, cSubject, aAttach )
  endif
   
Return lRet
 
********************************************************************************
STATIC Function Envia_Mail( oCfg, cFrom, cTo, cCC, cBCC, cMsg, cSubject, aAttach )

  local lRet := .f.
  local x, oMsg
/*
  cTo   := Destinatarios( cTo ) //--> PARA  
  cCC   := Destinatarios( cCC ) //--> COM COPIA
  cBCC  := Destinatarios( cBCC ) //--> COM COPIA OCULTA
*/

       TRY
         oMsg := CREATEOBJECT ( "CDO.Message" )
           WITH OBJECT oMsg
                :Configuration = oCfg
                :From = cFrom                
                :To = cTo
                :CC = cCC
                :BCC = cBCC
                
                :Subject = cSubject
                :TextBody = cMsg
                For x:= 1 To Len( aAttach )
                    if aAttach[x] <> NIL
                       :AddAttachment(AllTrim(aAttach[x]))
                    endif
                Next

//                ? cfrom, cto, cCC, cBCC, cSubject, cMsg

                :Send()
           END WITH
           lRet := .t.
       CATCH
           MsgInfo("No fue posible enviar el mensaje.", "Error." )
           lRet := .f.
       END
    
Return lRet
 
I wait serve you,

Regards
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: gmail

Post by James Bott »

Ariel,

I think Colin meant to read emails not send them.

James
Colin Haig
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am

Re: gmail

Post by Colin Haig »

Hi Ariel and James

I do need to read and save emails/attachments but also to send emails - so thanks for the code Ariel.

Regards

Colin
Post Reply