spartacus
13th July 2007, 16:02
Hi all,

I'm using the shell-command to send emails from Baan. The programm runs through a table in which it reads the users email adresses.
For every user there is a shell-command (BACKGROUND) which starts the "mailx"-client. Now it looks as though, that sometimes not all the users get this mail, altough I check the return-value of the shell command, which is always OK.

For test, I put a suspend(1000) into this loop and... it seems to work.

It looks as so, that Unix isn't fast enough to handle the data. To check this I wrote a shell-Script, which sends mail to 10 different addresses directly one after another. In that case all the recipients received their mail.

AT the moment I have no glue, from where the problem with the lost mails can come from? Does anybody have an idea?

mark_h
13th July 2007, 17:07
Have you tried run.prog versus shell command? Something like return.code = run.prog("sh",sh.cmd,RP_WAIT). Where sh.cmd is the mailx command. We use this in some of our programs rather than the shell command.

NPRao
13th July 2007, 20:57
Spartacus,

Since you are on Baan-5c you can explore to use - eMessage Connector (http://www.baanboard.com/programmers_manual_baanerp_help_emessage_connector_overview)

Nandan
15th July 2007, 22:03
Hi Spartacus,

I am working on similar project of sending email from Baan. I have taken approach of using socket programming to use SMTP protocol to send email. Sockets supported on Baan5 and above.

Please see the code below. This is not complete program, however it may help you.

check the following pages for more information on SMTP protocol

http://www.faqs.org/rfcs/rfc821.html
http://www2.rad.com/networks/2006/smtp/intro.htm


|******************************************************************************
|* etcomsock.mail 0 VRC B61C a dev
|* SMTP client testing
|* nbarad
|* 06/23/07 [19:33]
|******************************************************************************
|* Script Type: 0
|******************************************************************************
#define SMTP "25"
#define SERVER <SMTP email server name>
#define TO <To enail sepeated by comma>
#define FROM <From email>
#define CC <CC list sepeated by comma>

#define _debug 1
#define _ERLOG "/tmp/smtplog"

|Global varibales
long ret.socket

function main()
{
long error
string stream(4096)
string erp.host.name(20)

erp.host.name = hostname$()
ret.socket = sock.connect(SERVER, SMTP, 10)

receive(stream)
if stream(1;3) <> "220" then
|Did not receive the valid response
message("Email server not responded correctly")
endif
send.error("HELO " & erp.host.name)
receive(stream)
if err("HELO", stream) then
exit(1)
endif

send.error("MAIL FROM:<" & FROM & ">")
receive(stream)
if err("MAIL FROM", stream) then
exit(1)
endif

send.error("RCPT TO:<" & TO & ">")
receive(stream)
if err("RCPT TO", stream) then
exit(1)
endif

send.error("DATA")
receive(stream)
if err("DATA", stream) then
exit(1)
endif

send.error("To:" & TO)
send.error("Cc:" & CC)
send.error("Subject:" & "Test email " & dte$())
send.error("")
send.error("Test email")
send.error("Please ignore")
send.error(".")
receive(stream)

if err("BODY", stream) then
exit(1)
endif

err("STOP","")
|Now close socket
error = sock.close(ret.socket)

message("Socket")

}

function boolean send.error(const string i.stream)
{
long ret
long stream.len
string str.to.send(1) based

alloc.mem(str.to.send, len(i.stream) + 2)

str.to.send = i.stream & chr$(13) & chr$(10)
stream.len = len(str.to.send)
ret = sock.send(ret.socket, str.to.send , stream.len)

free.mem(str.to.send)

if ret <> stream.len then
|Server did not receive the data stream correctly
return(true)
endif
ret = sock.flush(ret.socket)
return(ret)
}

function receive(ref string o.stream())
{
long ret
string recv.str(1)

o.stream = ""
repeat
ret = sock.recv(ret.socket, recv.str, 1)
o.stream = o.stream & recv.str
until asc(recv.str) = 10 |end of stream = end of line
}

function boolean err(const string i.type,
const string i.reply)
{
static long errfp
long o.error

if _debug and not errfp then
errfp = seq.open(_ERLOG, "at")
endif

if errfp then
seq.puts(i.reply, errfp)
seq.flush(errfp)
endif

o.error = false
on case i.type
case "HELO":
case "MAIL FROM":
case "RCPT TO":
case "BODY":
if i.reply(1;3) <> "250" then
o.error = true
endif
break

case "DATA":
if i.reply(1;3) <> "354" then
o.error = true
endif
break
case "STOP":
if errfp then
seq.close(errfp)
endif
break
endcase

if o.error and errfp then
seq.close(errfp)
endif

return(o.error)
}

NPRao
16th July 2007, 06:19
Nandan,

In LN Tools, there are interfaces provided in CMF for SMTP, Outlook, Pager, Fenestra Connector.

I am not sure on the other Baan-5 releases, you would have to check with Baan support or the related documentation.

spartacus
16th July 2007, 12:05
Hi all,

thanks for your support. This are a lot of good ideas, also new techniques for me. To keep time and effort low, I will first try easy, quick things. So at the moment I think Marc advice will be the next thing I try. But first I will change my shell-call, I change the mode from SHELL_BACKGROUND to SHELL_NO_OUTPUT and hope the parent process will wait until child finishes.
If that doesn't work, I think I will try "run.prog()". Yes I know, "shell()" is outdated, but I stuck on things, from which I know they work :-)

I'm pretty sure I can solve the prob with the either the shell-mode, or run.prog(). If not... here are proposals enaugh :-)

Btw.: The try with suspend() doesn't work really.

Thanx