Forum > General

sending email not working

<< < (3/5) > >>

Awesome Programmer:

--- 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.  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 := 'msmpt';    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;
--- End quote ---

Thanks Remy for your reply.

When I run your code, it hangs up on L.LoadFromStream(sp.Output);. The program doesn't freeze or crash. It is just sitting at that line for an output from the command, but there is NO output from the command. Command executes and exits without no output. So, I not sure why this is.

Remy Lebeau:

--- Quote from: Awesome Programmer on June 13, 2024, 05:16:11 pm ---When I run your code, it hangs up on L.LoadFromStream(sp.Output);. The program doesn't freeze or crash. It is just sitting at that line for an output from the command, but there is NO output from the command. Command executes and exits without no output. So, I not sure why this is.

--- End quote ---

Does the original command line output anything to begin with?

Try adding the poStdErrToOutPut flag in the Options. Maybe the send is failing and outputting an error that you are not receiving yet.

rvk:
I'm not familiar with TProcess.Option poUsePipes but shouldn't you first write the TProcess.Input to the stream before you do TProcess.Execute?

(I don't think msmpt will wait for inout but just ends if the input is empty.)

MarkMLl:
I did this a few days ago, and have put a few Gb of text lines through the resulting streams:


--- 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";}};} ---    processObject := TProcess.Create(nil);    processObject.Executable := binPath + binName;    processObject.Options := [poUsePipes];    processObject.Execute;    Sleep(100);    if processObject.Running then begin      StatusBar := 'Starting...';      idleTimer1.Enabled := true    end else      FreeAndNil(processObject);        ...      FilterStreamToLines(ProcessObject.StdErr, lineStdErr, @stdErrLineCallback, true        , 0              );      FilterStreamToLines(ProcessObject.Output, lineOutput, @outputLineCallback, false        , 0              ) 
and


--- 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";}};} ---procedure FilterStreamToLines(const inputStream: TInputPipeStream; var line: ansistring;                        callback: PerLineCallback; timestamp: boolean= false; device: integer= -1);var  ch: ansichar; begin{ TODO : Read more than one character per loop. }   while inputStream.NumBytesAvailable > 0 do begin    inputStream.Read(ch, 1);    case ch of... 
So it does work reliably.

MarkMLl

rvk:
But isn't that for output streams.

Here the "hello world" is the inputstream filled AFTER Execute.
And if the command sees there is no bytes in the inputstream it could quit directly.
So my guess was that you first need to begin filling the inputstream before you do Execute.

Unless the command really waits before any input (which isn't certain).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version