Page 1 of 2

Rutina para enviar mails

PostPosted: Wed Dec 06, 2017 2:20 pm
by FiveWiDi
Hola a todos,

A ver si me pueden aconsejar una rutina para enviar mails desde nuestra aplicación, para que simplemente copiando el EXE de nuestra aplicación (o alguna DLL de terceros gratuita) en el pc del cliente pueda funcionar.

Vamos que no tenga que registrar nada, a lo sumo usar una DLL externa (simplemente copiándola).

Se me olvidaba, tengo que anexar ficheros en el mail.

Muchas gracias,

Re: Rutina para enviar mails

PostPosted: Wed Dec 06, 2017 2:44 pm
by karinha

Re: Rutina para enviar mails

PostPosted: Wed Dec 06, 2017 10:15 pm
by FiveWiDi


Gracias Karinha,

Debo estar viejo, pero no encuentro el botón "download" en los links.

Me refiero a una opción que no te obligue a registrarte o a instalar nada.

Gracias igualmente.

Re: Rutina para enviar mails

PostPosted: Wed Dec 06, 2017 10:16 pm
by FiveWiDi
Alguién del foro utiliza CDO para enviar mails?

No consigo que me funcione. Ha cambiado algo en Microsoft?

Gracias,

Re: Rutina para enviar mails

PostPosted: Thu Dec 07, 2017 10:52 am
by José Vicente Beltrán
FiveWiDi wrote:Alguién del foro utiliza CDO para enviar mails?

No consigo que me funcione. Ha cambiado algo en Microsoft?

Gracias,

Yo lo utilizo sin problemas en todas mis aplicaciones, lo saque del foro y solo lo configuré a mis necesidades. Te paso el código tal como lo tengo configurado por si es de ayuda.
Code: Select all  Expand view
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.
 

Saludos :shock:

Re: Rutina para enviar mails

PostPosted: Thu Dec 07, 2017 1:05 pm
by karinha
Hola, puedes descargar los archivos directamente desde PCToledo en este enlace:

http://www.pctoledo.com.br/forum/viewtopic.php?f=2&t=18800

http://www.pctoledo.com.br/forum/index.php

Saludos.

Re: Rutina para enviar mails

PostPosted: Fri Dec 08, 2017 11:40 am
by Willi Quintana
Hola amigos...
No me funciona SNDMAIL... a alguien le funciona???
SAlu2

Re: Rutina para enviar mails

PostPosted: Fri Dec 08, 2017 12:48 pm
by karinha
Image

Regards, saludos.

Re: Rutina para enviar mails

PostPosted: Sat Dec 09, 2017 9:49 am
by toninhofwi
https://www.emailarchitect.net/easendmail

is an activeX component and works perfect.

Re: Rutina para enviar mails

PostPosted: Sat Dec 09, 2017 12:39 pm
by MGA
Toninho, como funciona? tem um exemplo?

Re: Rutina para enviar mails

PostPosted: Sun Dec 10, 2017 4:18 am
by Willi Quintana
Hola Karinha
Error: 'D:\PRGS\SNDMAIL\PRG\SNDMAIL.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
* Linking errors *

Re: Rutina para enviar mails

PostPosted: Sun Dec 10, 2017 10:26 am
by cnavarro
Willi Quintana wrote:Hola Karinha
Error: 'D:\PRGS\SNDMAIL\PRG\SNDMAIL.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
* Linking errors *


Posiblemente sea una libreria para VS y estés utilizando Borland

Re: Rutina para enviar mails

PostPosted: Mon Dec 11, 2017 11:16 am
by karinha
Willi Quintana wrote:Hola Karinha
Error: 'D:\PRGS\SNDMAIL\PRG\SNDMAIL.LIB' contains invalid OMF record, type 0x21 (possibly COFF)
* Linking errors *



Willi, cual és la versión del FiveWin y Xharbour y Borlland que usas?

Compilo con:

Code: Select all  Expand view

C:\FWH1701\

C:\BCC72\

C:\XHARBOUR72\
 


Saludos.

Re: Rutina para enviar mails

PostPosted: Mon Dec 11, 2017 12:52 pm
by karinha
Con:

Code: Select all  Expand view

   "smtp.mail.yahoo.com"
 


No funciona. Que lástima.

Aqui, otro modelo:

http://linguagemclipper.com.br/book/export/html/48

https://groups.google.com/forum/#!topic/harbour-users/Q5XoaghBQI8

Saludos.

Re: Rutina para enviar mails

PostPosted: Mon Dec 11, 2017 7:13 pm
by karinha
Willi, intenta asi:

Code: Select all  Expand view

#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
 


Saludos.