#include "Fivewin.ch"
FUNCTION MAIN()
LOCAL cFrom := "tubelitefacturas@gmail.com"
LOCAL cServer := "smtp.gmail.com"
LOCAL cTo := "e.m.giordano@emagsoftware.it"
LOCAL cSubject := "Test message"
LOCAL cMessage := "This is a test message."
LOCAL cUser := "tubelitefacturas@gmail.com"
LOCAL cPassword := "SendCFDI_1"
LOCAL cPort := "465"
LOCAL lSSL := .T.
// ? HB_SENDMAIL( cServer, VAL( cPort ), cFrom, { cTo }, , , cMessage, cSubject, , cUser, cPassword, , , , , , , , , lSSL )
? SENDMAIL( cFrom, cServer, cTo, cSubject, cMessage, , , cUser, cPassword, , , cPort, , lSSL )
RETURN NIL
#command IF <condition> THEN <*statements*> => if <condition> ; <statements> ; end
STATIC 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 ) THEN cFrom = ["] + cSender + ["] + " <" + cFrom + ">"
oMsg:From = cFrom
oMsg:To = cTo
oMsg:Subject = cSubject
IF !EMPTY( aCc )
FOR i = 1 TO LEN( aCc )
IF i > 1 THEN cCc += ";"
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