***************************************************************
* Enviando emails *
* *
* Desenvolvedor: Ricardo de Moura Marques *
* email: ricardomouramarques@hotmail.com *
* *
* Agradecimentos ao Alessandro Seribeli Barreto - "Ale SB" *
* pelo código inicial, sem o qual, esse projeto *
* não seria possível *
* *
***************************************************************
#include "fivewin.ch"
memvar correo
Static cAttach := ""
Static aAttach := {}
********************************************************************************
Function Main()
local cdestino :="chino72vale@hotmail.com;ferropuerto@ferropuerto.com"
local carchivos:={"C:\fwh\samples\hola.txt","C:\fwh\samples\texto.txt"}
local ctxt :="a mandar un correo"
local csubject :="correo de pruebas "
local cbmp :="c:\faceleben\kasto2.bmp"
local chtml :="c:\faceleben\suave.html"
if config_email(cdestino, carchivos, ctxt, csubject,cbmp,chtml)
? "se mando el correo"
else
? " no se mando correo"
endif
Return Nil
********************************************************************************
Function Config_eMail(cdest, cfiles, ctxt, csubject, cbmp, chtml )
Local cUser,cPass,cRemt, cCC, cCCO
local lRet := .f.
local oCfg, oError
local cServ :="smtp.xxxxx.com" // servidor smtp
local nPort :=25 // puerto
local lAut :=.t.
local lSSL :=.f.
if cfiles=nil
aAttach:={}
else
aAttach:=cfiles
endif
cPass:="xxxxxx" //usuario
cuser:="xxxxx@xxxxx.com" //correo del quien manda
ccc:=""
ccco:=""
cRemt:=cuser
// aAttach:=CFILES // serian los archivos anexados we
if Empty(cPass) .or. Empty(cRemt) .or. empty(cDest)
? "falta datos para mandar correo,,,, destino/ remitente / usuario checar "
return .f.
endif
? "entramos a la configucraion"
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 se pudo enviar 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, "Atención" )
END
//--> FIM DAS CONFIGURAÇOES.
if lRet
lRet := Envia_eMail(oCfg,cRemt,cDest, cCC, cCCO, cTxt, cSubject, cbmp, chtml)
endif
Return lRet
********************************************************************************
Function Envia_eMail(oCfg,cFrom, cTo, cCC, cBCC, cMsg, cSubject, cbmp, chtml)
local cToken
local lRet := .f. , Omsg , x, i, loBP
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
:HTMLBody = "<p><img src='cid:id_imagen10'></p>" +"<p>La imagen de arriba esta embebida en el mensaje.</p>"
loBP:=:AddRelatedBodyPart(cbmp, "id_imagen10", 1)
WITH OBJECT loBP:Fields
:Item("urn:schemas:mailheader:Content-ID")= "id_imagen10"
:Update()
END WITH
:CreateMHTMLBody("File://"+chtml,0)
:Send()
END WITH
lRet := .t.
CATCH
// MsgInfo("No se pudo mandar la factura ")
lRet := .f.
END
Return lRet