gmail

gmail

Postby Colin Haig » Fri Apr 05, 2013 11:43 pm

Hi All

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

Cheers


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

Re: gmail

Postby Ariel » Sun Apr 07, 2013 12:00 pm

Colin,

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

Code: Select all  Expand view

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
Ariel
 
Posts: 376
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: gmail

Postby James Bott » Sun Apr 07, 2013 3:43 pm

Ariel,

I think Colin meant to read emails not send them.

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

Re: gmail

Postby Colin Haig » Sun Apr 07, 2013 10:41 pm

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
Colin Haig
 
Posts: 310
Joined: Mon Oct 10, 2005 5:10 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 77 guests