Usando Microsoft CDO pra emails
Enviado: 05 Jun 2024 11:22
Ainda não me acertei com ele.
Andam acontecendo algumas falhas sem sentido.
Faz tempo tenho ele no aplicativo, mas só agora tentando colocar em uso.
Minha classe é antiga, do tempo que BLAT.EXE ou BLAT.DLL ainda eram opção.
Tem a opção de usar harbour, blat ou cdo.
Como exemplo: tem email com zip que não vai mas com harbour vai, ao mesmo tempo que com outro email vai.
A última linha de configuração comentada acrescentei depois, ainda na dúvida sobre qual opção usar.
Andam acontecendo algumas falhas sem sentido.
Faz tempo tenho ele no aplicativo, mas só agora tentando colocar em uso.
Minha classe é antiga, do tempo que BLAT.EXE ou BLAT.DLL ainda eram opção.
Tem a opção de usar harbour, blat ou cdo.
Código: Selecionar todos
#define CDO_SEND_USING_PICKUP 1 // email client program
#define CDO_SEND_USING_PORT 2 // direct to internet
#define CDO_ANONYMOUS 0
#define CDO_BASIC 1 // clear text
#define CDO_NTLM 2
#define CDO_DSN_DEFAULT 0 // none
#define CDO_DSN_NEVER 1 // none
#define CDO_DSN_FAILURE 2 // failure
#define CDO_DSN_SUCCESS 4 // success
#define CDO_DSN_DELAY 8 // delay
#define CDO_DSN_SUCCESS_FAIL_OR_DELAY 14 // none + success + failure + delay
METHOD SendUsingCDO() CLASS ze_SendMailClass
LOCAL oMessage, oConfiguration, oElement, lOk, cText, e
oConfiguration := win_OleCreateObject( "CDO.Configuration" )
WITH OBJECT oConfiguration
:Fields( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := CDO_SEND_USING_PORT
:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := ::cServer
:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := CDO_BASIC
:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := ::nPort
:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" ):Value := ::nTimeOut / 1000
:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := ::lWithSSL
:Fields( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := ::cFrom
:Fields( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := ::cPassword
//:Fields( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := .T.
:Fields:Update()
ENDWITH
oMessage := win_OleCreateObject( "CDO.Message" )
WITH OBJECT oMessage
:Configuration := oConfiguration
:To := ArrayToList( ::acTo, ";" )
:From := ::cFrom
:Subject := ::cSubject
// 0 default no dsn commands
// 1 no dsn commands at all
// 2 return a dsn if fail
// 4 return a dsn if sucess
// 8 return a dsn if delayed
// 14 return a dsn for all
:DSNOptions := 0
IF File( ::cFileBody )
:HtmlBody := MemoRead( ::cFileBody )
ELSE
:HtmlBody := ::cFileBody
ENDIF
FOR EACH oElement IN ::acAttachment
:AddAttachment( iif( "\" $ oElement, "", hb_cwd() ) + oElement )
NEXT
:Fields( "urn:schemas:mailheader:disposition-notification-to" ):Value := ::cFrom
:Fields:Update()
lOk := .F.
BEGIN SEQUENCE WITH __BreakBlock()
oMessage:Send()
lOk := .T.
RECOVER USING e
IF ValType( e:Description ) == "C"
Errorsys_WriteErrorLog( e:Description, 2 )
ENDIF
ENDSEQUENCE
IF ! lOk
cText := "Error on email " + ::cFrom + hb_Eol() + ::cSubject + hb_Eol() + hb_ValToExp( ::acTo ) + hb_Eol()
IF ! Empty( cText )
Errorsys_WriteErrorLog( cText )
ENDIF
lOk := .T.
ENDIF
ENDWITH
RETURN lOk
A última linha de configuração comentada acrescentei depois, ainda na dúvida sobre qual opção usar.