CDO email
Posted: Tue Jun 02, 2015 4:21 pm
Hi, I try to send email using CDO but sometimes send and sometimes not, what I do wrong?
Thanks
local lRet := .f.
local oCfg, oError
local cServ := "smtp.rotamaxgroup.com"
local nPort := "587"
local lAut := .t.
local lSSL := .f.
local cPass := "XXXXXX"
cUser := Alltrim(_cUser)
cRemt := Alltrim(_cUser)
TRY
oCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/config ... smtpserver" ):Value := cServ
:Item( "http://schemas.microsoft.com/cdo/config ... serverport" ):Value := nPort
:Item( "http://schemas.microsoft.com/cdo/config ... /sendusing" ):Value := 2
:Item( "http://schemas.microsoft.com/cdo/config ... thenticate" ):Value := lAut
:Item( "http://schemas.microsoft.com/cdo/config ... smtpusessl" ):Value := lSSL
:Item( "http://schemas.microsoft.com/cdo/config ... ndusername" ):Value := cUser
:Item( "http://schemas.microsoft.com/cdo/config ... ndpassword" ):Value := cPass
:Update()
END WITH
lRet := .t.
CATCH oError
MsgInfo( "Não Foi possível Enviar o 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, "Atenção" )
END
////////////////////////
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( cAttach )
if cAttach[x] <> NIL
:AddAttachment(cAttach[x])
endif
Next
:Send()
END WITH
lRet := .t.
CATCH
// MsgInfo("Não foi possível enviar a mensagem")
lRet := .f.
END
Thanks
local lRet := .f.
local oCfg, oError
local cServ := "smtp.rotamaxgroup.com"
local nPort := "587"
local lAut := .t.
local lSSL := .f.
local cPass := "XXXXXX"
cUser := Alltrim(_cUser)
cRemt := Alltrim(_cUser)
TRY
oCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/config ... smtpserver" ):Value := cServ
:Item( "http://schemas.microsoft.com/cdo/config ... serverport" ):Value := nPort
:Item( "http://schemas.microsoft.com/cdo/config ... /sendusing" ):Value := 2
:Item( "http://schemas.microsoft.com/cdo/config ... thenticate" ):Value := lAut
:Item( "http://schemas.microsoft.com/cdo/config ... smtpusessl" ):Value := lSSL
:Item( "http://schemas.microsoft.com/cdo/config ... ndusername" ):Value := cUser
:Item( "http://schemas.microsoft.com/cdo/config ... ndpassword" ):Value := cPass
:Update()
END WITH
lRet := .t.
CATCH oError
MsgInfo( "Não Foi possível Enviar o 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, "Atenção" )
END
////////////////////////
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( cAttach )
if cAttach[x] <> NIL
:AddAttachment(cAttach[x])
endif
Next
:Send()
END WITH
lRet := .t.
CATCH
// MsgInfo("Não foi possível enviar a mensagem")
lRet := .f.
END