karinha wrote:Mira se sirve:
https://www.4shared.com/zip/9wQ0A3UHce/RMAIL.html
https://www.4shared.com/zip/yOCLl-p-ba/SNDMAIL.html
Saludos.
FiveWiDi wrote:Alguién del foro utiliza CDO para enviar mails?
No consigo que me funcione. Ha cambiado algo en Microsoft?
Gracias,
Function EnviaMailCDO(aDestinos, cAsunto, cTexto, aAdjuntos, aCC, aBcc, lRespuesta )
Local oEmailCfg, oEmailMsg, oError, nFor, i, loBP
local cDatos := GetSysDir(), oIni, nDefecto := 1
local cIniFile := cDatos+"\PREFEREN.INI"
Local lEncriptaPass := .f. //GetPvProfString("CORREO","EncriptaPass" ,.f., cIniFile)
Local cServer := "" //GetPvProfString("CORREO","servidor" ,"", cIniFile)
Local nPortEmail := "25" //VAL(GetPvProfString("CORREO","Puerto","25", cIniFile))
Local cEmailFrom := "" //GetPvProfString("CORREO","Remitente" ,"", cIniFile)
Local cEmailUser := "" //GetPvProfString("CORREO","Usuario" ,"", cIniFile)
Local cEmailPass := "" //GetPvProfString("CORREO","Contra" ,"", cIniFile)
Local lEmailSSL := .f. //GetPvProfString("CORREO","SSL" , .f., cIniFile)
local lAutentificar := .t.
local nTiempo := "30"
local cLogo := ""
local cFirma := ""
DEFAULT aAdjuntos:= {}
DEFAULT cAsunto :=""
DEFAULT cTexto := ""
if Empty(aDestinos ) .or. !("@"$aDestinos[1])
msgStop("Es necesario indicar al menos un destinatario.", "Aviso")
Return .f.
endif
if !empty( aAdjuntos )
for nFor = 1 to LEN(aAdjuntos)
if !file( aAdjuntos[nFor] )
MsgStop("No existe el archivo para adjuntar:"+CRLF+;
aAdjuntos[nFor], "Problema" )
return .f.
endif
next nFor
endif
INI oIni FILE RutaIniDatos()+"\MAILJVBP.INI"
GET nDefecto SECTION "CORREO" ENTRY "CuentaDefecto" OF oIni
ENDINI
INI oIni FILE cDatos+"\PREFEREN.INI"
GET cServer SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Servidor" OF oIni
GET cEmailFrom SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Remitente" OF oIni
GET cEmailUser SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Usuario" OF oIni
GET cEmailPass SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Contra" OF oIni
GET nTiempo SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Tiempo" OF oIni DEFAULT "30"
GET nPortEmail SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Puerto" OF oIni DEFAULT "25"
GET lEncriptaPass SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "EncriptaPass" OF oIni DEFAULT .t.
GET lAutentificar SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Autentificar" OF oIni DEFAULT .t.
GET lEmailSSL SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "SSL" OF oIni DEFAULT .f.
GET cLogo SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "Logo" OF oIni
GET cFirma SECTION "CORREOCDO_CUENTA"+str(nDefecto, 1) ENTRY "FirmaTxt" OF oIni
ENDINI
if empty(cServer) .or. empty(cEmailFrom)
MsgStop("Debe configurar previamente los datos del correo.", "Aviso")
return .f.
endif
cLogo := alltrim(cLogo)
cFirma := alltrim(cFirma)
cTexto := ConvHTML(cTexto, cLogo, cFirma)
nTiempo := VAL(nTiempo)
nPortEmail := VAL(nPortEmail)
cEmailPass := iif(lEncriptaPass, PADR(DECRYPT(cEmailPass) , 75, " "), PADR(cEmailPass , 75, " "))
cEmailPass := ALLTRIM(cEmailPass)
TRY
oEmailCfg := CREATEOBJECT( "CDO.Configuration" )
WITH OBJECT oEmailCfg:Fields
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value := cServer //"smtp.fibertel.com.ar" //"smtp.live.com" ///"smtp.gmail.com"
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := nPortEmail //25 //465
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value := 2 // Remote SMTP = 2, local = 1
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value := lAutentificar
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value := lEmailSSL
:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value := cEmailUser
:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cEmailPass
:Item( "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"):Value := nTiempo
:Update()
END WITH
CATCH oError
MsgInfo( "Error al configurar el correo" + 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 + ;
"Message: " + oError:Description, "Error de configuracion CDO" )
END
oError:=NIL
for nFor = 1 to LEN(aDestinos)
TRY
oEmailMsg := CREATEOBJECT ( "CDO.Message" )
WITH OBJECT oEmailMsg
:Configuration = oEmailCfg
//:From = chr(34)+'jvbp '+chr(34) + '<'+cEmailFrom+'>' // This will be displayed in the From (The email id does not appear)
:From = cEmailFrom // remitente
:To = aDestinos[nFor] // destinatarios
iif(!empty(aCC) , :Cc = aCC , ) // con copia
iif(!empty(aBcc), :BCC = aBCC, ) // con copia oculta
:Subject = cAsunto // sujeto
//:TextBody = cTexto // formato Texto
//:CreateMHTMLBody("file:///E:\prueba.htm", 0) //[, flags [, username, password]] // envia una pagina HTML ya creada
:AutoGenerateTextBody = .T. // cuando el cliente no acepta HTML genera un formato de texto
:HTMLBody = cTexto // formato HTML
iif(!empty(cLogo), loBP:=:AddRelatedBodyPart( cLogo, "id_imagen1", 0), )
for i = 1 to len(aAdjuntos)
:AddAttachment(aAdjuntos[i]) // adjuntos
next i
if lRespuesta
:MDNRequested = .T. // Requiere respuesta
:fields( "urn:schemas:mailheader:disposition-notification-to" ):Value := cEmailFrom
:fields( "urn:schemas:mailheader:return-receipt-to" ):Value := cEmailFrom
:fields:Update()
endif
:Send()
END WITH
CATCH oError
MsgInfo("Error al enviar el mensaje" + 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 +;
"Message: " + oError:Description, "Error al enviar el mensaje" )
return .f.
END
next nFor
Return .T.
Willi Quintana wrote:Hola Karinha
Error: 'D:\PRGS\SNDMAIL\PRG\SNDMAIL.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
* Linking errors *
Willi Quintana wrote:Hola Karinha
Error: 'D:\PRGS\SNDMAIL\PRG\SNDMAIL.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
* Linking errors *
C:\FWH1701\
C:\BCC72\
C:\XHARBOUR72\
"smtp.mail.yahoo.com"
#include "Fivewin.ch"
STATIC hDll
FUNCTION MAIN()
LOCAL cFrom := "joao@pleno.com.br"
LOCAL cServer := "smtp.pleno.com.br"
LOCAL cTo := "joao@pleno.com.br"
LOCAL cSubjeCt := "Test with sendmail CDO"
LOCAL cMessage := "Test with sendmail - Email Body"
LOCAL cSender := "joao@pleno.com.br"
LOCAL cUser := "joao@pleno.com.br"
LOCAL cPassword := "XXXXXXX"
LOCAL aAttach := {}
LOCAL aCc := "" //???
LOCAL lHtml := .F.
LOCAL cPort := "587"
LOCAL lNotification := .F. // cFrom
LOCAL lRet
LOCAL lSSL := .F.
//lRet := SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, cSender, cUser, cPassword, aAttach, aCc, lHtml, cPort, lNotification )
// USING CDO
lRet := SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort, lNotification, lSSL )
IF lRet
? "Message sent successfully perfect with FWH17.01"
ELSE
? "Unsent message check windows live mail"
ENDIF
RETURN NIL
// viewtopic.php?f=3&t=21490#p191444
FUNCTION SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort, lNotification, lSSL )
LOCAL lOk := .F.
LOCAL oCfg, oMsg
LOCAL cCc := ""
LOCAL i
DEFAULT lHtml := "<html" $ LOWER( cMessage )
DEFAULT lNotification := .F.
DEFAULT lSSL := .T.
TRY
oCfg = CREATEOBJECT( "CDO.Configuration" )
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver" ):Value = cServer
IF !EMPTY( cPort )
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ):Value := VAL( cPort )
ENDIF
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusing" ):Value = 2
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .F.
IF !EMPTY( cUser ) .AND. !EMPTY( cPassword )
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" ):Value = .T.
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendusername" ):Value = cUser
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ):Value := cPassword
oCfg:Item( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ):Value = lSSL
ENDIF
oCfg:Update()
oMsg = CREATEOBJECT( "CDO.Message" )
oMsg:Configuration = oCfg
IF !EMPTY( cSender )
cFrom = ["] + cSender + ["] + " <" + cFrom + ">"
ENDIF
oMsg:From = cFrom
oMsg:To = cTo
oMsg:Subject = cSubject
IF !EMPTY( aCc )
FOR i = 1 TO LEN( aCc )
IF i > 1
cCc += ";"
ENDIF
cCc += aCc[ i ]
NEXT
oMsg:CC = cCc
ENDIF
IF !lHtml
oMsg:TextBody = cMessage
ELSE
oMsg:HTMLBody = cMessage
ENDIF
IF !EMPTY( aAttach )
FOR i = 1 TO LEN( aAttach )
oMsg:AddAttachment( aAttach[ i ] )
NEXT
ENDIF
IF lNotification
oMsg:Fields:Item( "urn:schemas:mailheader:disposition-notification-to" ):Value = cFrom
oMsg:Fields:Update()
ENDIF
oMsg:Send()
lOk = .T.
CATCH
END
RETURN lOk
/*
FUNCTION SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, cSender, cUser, cPassword, aAttach, aCc, lHtml, cPort, lNotification )
LOCAL cMsgFile := CTEMPFILE()
LOCAL cCmd := "SndMail -f " + cFrom + " -X " + cServer + " -r " + cTo + " -s " + ["] + cSubject + ["] + " -b " + cMsgFile
LOCAL nRes
LOCAL i
DEFAULT lHtml := "<html" $ LOWER( cMessage )
MEMOWRIT( cMsgFile, cMessage + CRLF )
IF !EMPTY( aAttach )
FOR i = 1 TO LEN( aAttach )
cCmd += " -a " + ["] + aAttach[ i ] + ["]
NEXT
ENDIF
IF !EMPTY( cSender )
cCmd += " -F " + ["] + cSender + ["]
ENDIF
IF !EMPTY( cUser )
cCmd += " -h LOGIN -u " + cUser
ENDIF
IF !EMPTY( cPassword )
cCmd += " -p " + cPassword
ENDIF
IF !EMPTY( aCc )
FOR i = 1 TO LEN( aCc )
cCmd += " -c " + ["] + aCc[ i ] + ["]
NEXT
ENDIF
IF lHtml
cCmd += " -H"
ENDIF
IF !EMPTY( cPort )
cCmd += " -P " + cPort
ENDIF
IF !EMPTY( lNotification )
cCmd += " -t " + ["] + "Disposition-Notification-To: " + cFrom + ["]
ENDIF
hDLL = LOADLIBRARY( "sndmail.dll" )
IF hDll = 0
? [Install sndmail.dll.. ]
__QUIT()
ELSE
SMTPLIBOPEN() // OPEN sndmail.dll
ENDIF
nRes = SMTPSENDMAIL( cCmd )
SMTPLIBCLOSE()
FREELIBRARY( hDLL )
FERASE( cMsgFile )
RETURN nRes = 0
*/
/*
DLL STATIC FUNCTION SMTPLIBOPEN() AS VOID;
PASCAL FROM "USmtpLibOpen" LIB hDll
DLL STATIC FUNCTION SMTPSENDMAIL( cCmd AS STRING ) AS LONG;
PASCAL FROM "USmtpCmdLineSendMail" LIB hDll
DLL STATIC FUNCTION SMTPLIBCLOSE() AS VOID;
PASCAL FROM "USmtpLibClose" LIB hDll
*/
// END OF PROGRAM
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot], Willi Quintana and 12 guests