*!* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*!* Copyright (c) ARG-Software Design Lab. 2001-2002
*!* All rights reserved.
*!*
*!* Simple MessageSender class,
*!*
*!* This sample code is FREEWARE.
*!*
*!*
*!* Author: Alex Grigorjev
*!* E-mail: AlexG@arg.kirov.ru
*!* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
oSender = CreateObject( "MessageSender")
oSender.Recipient = "localhost"
oSender.ReturnAddress = "ARG's Message_Sender"
?oSender.Send( "How are you doing?" + ;
Chr(13) + Chr(10) + ;
Chr(13) + Chr(10) + ;
"This is a sample message sent by ARG's MessageSender")
Define Class MessageSender As Custom
Recipient = ""
ReturnAddress = ""
UseNETSEND = .F.
Procedure Init()
DoDefault()
EndProc
Procedure Destroy
DoDefault()
EndProc
Procedure Error(nError, cMethod, nLine)
EndProc
*- If the function succeeds, the return value is NERR_Success = 0.
Function Send( tcMessage)
Local lnResult
lnResult = 0
With This
If Type( ".Recipient") != "C" Or Empty( .Recipient)
&& no recipient
Return -1
EndIf
If Type( "m.tcMessage") != "C" Or Empty( m.tcMessage)
&& nothing to send
Return -2
EndIf
If .UseNetSend
Local lcCmd, loShell
lcCmd = "NET SEND " + AllTrim( .Recipient) + ' "' + AllTrim( m.tcMessage) + '"'
loShell = CreateObject( "WScript.Shell")
If Type( "m.loShell") = "O" And !IsNull( m.loShell)
lnResult = m.loShell.Run( m.lcCmd, 0, .T.)
Else
&& cannot create Shell object, will try Fox RUN command
lcCmd = m.lcCmd
!&lcCmd
&& or ShellExecute
* Declare Integer ShellExecute In Shell32 Integer, String, String, String, String, Integer
* ShellExecute( 0, "open", "cmd.exe", "/c" + m.lcCmd, NULL, 2)
* Or
* lcCmd = SubStr( m.lcCmd, 5)
* ShellExecute( 0, "open", "net.exe", m.lcCmd, NULL, 2)
EndIf
Else
Declare Integer NetMessageBufferSend In NetAPI32 ;
String @ servername, ;
String @ msgname, ;
String @ fromname, ;
String @ buf, ;
Integer buflen
Local lcMsgName, lcFrom, lnMsgLen, lcMsgBuf
lcFrom = .ReturnAddress
If Type( "m.lcFrom") != "C" Or Empty( m.lcFrom)
lcFrom = "Unknown"
EndIf
lcMsgName = StrConv( AllTrim( .Recipient) + Chr( 0), 5)
lcFrom = StrConv( AllTrim( m.lcFrom) + Chr(0), 5)
lcMsgBuf = StrConv( AllTrim( m.tcMessage) + Chr(0), 5)
lnMsgLen = Len( m.lcMsgBuf)
lcMsgBuf = m.lcMsgBuf + Chr(0) + Chr(0)
lnResult = NetMessageBufferSend( .NULL., m.lcMsgName, m.lcFrom, m.lcMsgBuf, m.lnMsgLen)
EndIf
EndWith
Return m.lnResult
EndFunc
EndDefine