#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
Baxajaun wrote:change hDLL for hLib.
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 )
Willi Quintana wrote:Hi,,, (thanks Giordano)
Willi Quintana wrote:any example with hotmail???
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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 46 guests