Forum > General

sending email not working

<< < (2/5) > >>

Remy Lebeau:

--- Quote from: Awesome Programmer on June 12, 2024, 08:21:04 pm ---Can someone tell me what is wrong with the above PASCAL CODE?

--- End quote ---

echo is not an executable that you can run directly.  It is a built-in command of the terminal itself.  You are using the terminal's pipe operator to send the output of echo to the STDIN stream of the msmpt executable.  So you need to do the same thing with TProcess, eg:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function SendMail:Boolean;var  sp: TProcess;  L: TStringList;begin  L := TStringList.Create;  sp := TProcess.Create(nil);  try    sp.Options := [poUsePipes];    sp.Executable := 'msmtp';    sp.Parameters.Add('--from=james@james.com');    sp.Parameters.Add('1234567899@tmomail.net');    sp.Execute;    L.Text := 'Hello World';    L.SaveToStream(sp.Input);    L.Clear;    L.LoadFromStream(sp.Output);    WriteLn(L.Text);  finally    sp.free;    L.free;  end;  Result := true;end;

MarkMLl:

--- Quote from: Awesome Programmer on June 12, 2024, 10:08:27 pm ---Yes, RTFM:

LOL... for your information, I always do my best to read and re-read TFM. Sometimes, things don't always work like they say in the BOOK... I learned this after coding for over 20 years.

I came up with a workaround and it works; created a shell script file and then execute the script file from my Lazarus program.

 :D :D :D :D

--- End quote ---

Sorry :-) A shell script will work, but I've also used pipelines etc. to good effect by specifying the shell (sh, bash or WHY) explicitly.

MarkMLl

rvk:

--- Quote from: Remy Lebeau on June 12, 2024, 10:10:58 pm ---
--- Quote from: Awesome Programmer on June 12, 2024, 08:21:04 pm ---Can someone tell me what is wrong with the above PASCAL CODE?

--- End quote ---

echo is not an executable that you can run directly.  It is a built-in command of the terminal itself. 
--- End quote ---
Not an executable???


--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---pi@space01:~ $ whereis echoecho: /usr/bin/echo /usr/share/man/man1/echo.1.gzpi@space01:~ $ ls /usr/bin/echo -ltr-rwxr-xr-x 1 root root 35632 Sep 22  2020 /usr/bin/echo*pi@space01:~ $ file /usr/bin/echo/usr/bin/echo: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=bbd46f97ea84f6e4971a0cff6a54ffa85435f1a4, for GNU/Linux 3.7.0, stripped 
msmtp is a Linux command so I assume this is Linux and not Windows.


--- Quote from: Remy Lebeau on June 12, 2024, 10:10:58 pm ---You are using the terminal's pipe operator to send the output of echo to the STDIN stream of the msmpt executable.

--- End quote ---
Yes, the problem in the original post is that the pipe and second command were given as parameter to the echo command. That doesn't work. You need a shell (bash, sh) to be able to use pipe like that. Or handle the input/output streams yourself.

Running this complete line as parameter itself with bash as command might be easier.

Remy Lebeau:

--- Quote from: rvk on June 12, 2024, 11:41:08 pm ---
--- Quote from: Remy Lebeau on June 12, 2024, 10:10:58 pm ---echo is not an executable that you can run directly.  It is a built-in command of the terminal itself. 
--- End quote ---
Not an executable???


--- Code: Bash  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---pi@space01:~ $ whereis echoecho: /usr/bin/echo /usr/share/man/man1/echo.1.gzpi@space01:~ $ ls /usr/bin/echo -ltr-rwxr-xr-x 1 root root 35632 Sep 22  2020 /usr/bin/echo*pi@space01:~ $ file /usr/bin/echo/usr/bin/echo: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=bbd46f97ea84f6e4971a0cff6a54ffa85435f1a4, for GNU/Linux 3.7.0, stripped 
--- End quote ---

OK. It is an executable on some platforms, but not on others.  Doesn't change the rest of my earlier reply.  The code should not be executing echo but rather executing msmtp instead.

MarkMLl:

--- Quote from: Remy Lebeau on June 13, 2024, 12:01:56 am ---OK. It is an executable on some platforms, but not on others.  Doesn't change the rest of my earlier reply.  The code should not be executing echo but rather executing msmtp instead.

--- End quote ---

Like time, echo exists as both a shell internal command and a binary.

So you're both right, stop snarling at each other :-)

MarkMLl

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version