Page 1 of 2

A tool to send email ?

Posted: Fri May 06, 2011 5:11 pm
by Armando
Hi friends:

Do you know a very good class, function, lib, dll or tool to send emails from my app, my tools: FWH0810 and xHarbour build 1.1.0 Intl. (SimpLex) (Rev. 6195)?

With best regards

Re: A tool to send email ?

Posted: Fri May 06, 2011 8:04 pm
by Enrico Maria Giordano

Re: A tool to send email ?

Posted: Sat May 07, 2011 1:34 am
by Armando
Thanks a lot Enrico.

Is it possible a small sample :oops:

Best regards

Re: A tool to send email ?

Posted: Sat May 07, 2011 10:44 am
by Enrico Maria Giordano
Here it is:

Code: Select all

#include "Fivewin.ch"


STATIC hLib


FUNCTION MAIN()

    LOCAL cFrom     := ""
    LOCAL cServer   := ""
    LOCAL cTo       := ""
    LOCAL cSubjeCt  := ""
    LOCAL cMessage  := ""
    LOCAL cSender   := ""
    LOCAL cUser     := ""
    LOCAL cPassword := ""

    ? SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, , cSender, cUser, cPassword )

    RETURN NIL


FUNCTION SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, 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" )

    SMTPLIBOPEN()

    nRes = SMTPSENDMAIL( cCmd )

    SMTPLIBCLOSE()

    FREELIBRARY( hDLL )

    FERASE( cMsgFile )

    RETURN nRes = 0


DLL STATIC FUNCTION SMTPLIBOPEN() AS VOID;
    PASCAL FROM "USmtpLibOpen" LIB hLib

DLL STATIC FUNCTION SMTPSENDMAIL( cCmd AS STRING ) AS LONG;
    PASCAL FROM "USmtpCmdLineSendMail" LIB hLib

DLL STATIC FUNCTION SMTPLIBCLOSE() AS VOID;
    PASCAL FROM "USmtpLibClose" LIB hLib
EMG

Re: A tool to send email ?

Posted: Sat May 07, 2011 12:07 pm
by Armando
Enrico:

Thanks so much for your sample, I'll test it.

Best regards

Re: A tool to send email ?

Posted: Tue May 10, 2011 9:25 am
by Baxajaun
Enrico,

thanks a lot for the sample and your help !!!

Armando,

change hDLL for hLib.

Best regards,

Felix

Re: A tool to send email ?

Posted: Tue May 10, 2011 9:47 am
by Enrico Maria Giordano
Baxajaun wrote:change hDLL for hLib.
Sorry, my fault.

EMG

Re: A tool to send email ?

Posted: Tue May 10, 2011 4:20 pm
by Willi Quintana
Hi friends...

came out this error when compiling

Error: 'D:\SOFT\SNDMAIL\SNDMAIL-2.5\SNDMAIL.LIB' contains invalid OMF record,

Re: A tool to send email ?

Posted: Tue May 10, 2011 4:26 pm
by Enrico Maria Giordano
You don't have to link sndmail.lib. Use sndmail.dll only.

EMG

Re: A tool to send email ?

Posted: Tue May 10, 2011 4:56 pm
by Willi Quintana
Hi,,, (thanks Giordano)
any example with hotmail???
this is my code:

Code: Select all

 cFrom     := "cliente@hotmail.com"
 cServer   := "smtp.live.com"
 cTo       := "willi@hotmail.com"
 cSubject  := "error system"
 cMessage  := memoread("error.log")
 cSender   := ""
 cUserm    := "cliente"
 cPassm    := "12345678"
 ? SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, , cSender, cUserm, cPassm )
 
return .F.

suggestions??

Re: A tool to send email ?

Posted: Tue May 10, 2011 8:15 pm
by Enrico Maria Giordano
Willi Quintana wrote:Hi,,, (thanks Giordano)
My name is Enrico. :-)
Willi Quintana wrote:any example with hotmail???
No, sorry. It should work. Does it work using Outlook or similar email apps?

EMG

Re: A tool to send email ?

Posted: Thu May 19, 2011 3:45 pm
by zazibr
hotmail

-P port Set SMTP port { 25 }

port 25 or 995

Re: A tool to send email ?

Posted: Mon Jun 13, 2016 1:50 pm
by ukoenig
Enrico,

I tested Your sample, but nothing happens

FUNCTION MAIN()
// AOL SMTP-Server ( infos from internet ):
// smtp.de.aol.com for emails ending with aol.com
// login for the SMTP-Server is needed.
// username and password

LOCAL cFrom := "Uwe"
LOCAL cServer := "smtp.de.aol.com"
LOCAL cTo := "esckoenig@aol.com" // my email for testing the mailbox for incomming emails
LOCAL cSubjeCt := "Test"
LOCAL cMessage := "Test"
LOCAL cSender := "Uwe"
LOCAL cUser := "aoluser" // adding my username
LOCAL cPassword := "aolpassword" // adding my password

? SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, , cSender, cUser, cPassword )

RETURN NIL
FUNCTION SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, aAttach, cSender, cUser, cPassword, aCc, lHtml, cPort, lNotification )
...
...


maybe something missing or not possible to use it ?
or is there maybe another working sample in the meantime
because the post is dated 2011 ?

regards
Uwe :?:

Re: A tool to send email ?

Posted: Mon Jun 13, 2016 2:20 pm
by Enrico Maria Giordano
I don't use sndmail.dll any longer. Now I'm using CDO.Message:

Code: Select all

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          := .F.

    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
EMG

Re: A tool to send email ?

Posted: Mon Jun 13, 2016 2:25 pm
by ukoenig
Enrico,

thank You very much for the sample.
I will add it to my downloadsection and test it

regards
Uwe :D