Recent

Author Topic: sending email not working  (Read 3232 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8036
Re: sending email not working
« Reply #15 on: June 13, 2024, 07:58:40 pm »
Yes, that is for output and works with a program that runs until it gets a sigint or sigterm.

If a program is terminating immediately it sees no input and doesn't have an option to run until it sees an explicit EOF (i.e. pipe closure etc.) then it's obviously a problem. OTOH my experience with things like sendmail was that they ran until they got an explicit EOM, e.g.  .  as the first character of a line.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1430
    • Lebeau Software
Re: sending email not working
« Reply #16 on: June 14, 2024, 06:39:28 am »
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).

According to https://marlam.de/msmtp/msmtp.html:

Quote
In its default mode of operation, it reads a mail from standard input...

So, it's safe to assume that it waits for the caller to enter input so it knows what to send.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

TRon

  • Hero Member
  • *****
  • Posts: 3647
Re: sending email not working
« Reply #17 on: June 14, 2024, 06:54:47 am »
I am also not familiar with the details of such piping as shown by your example Remy but could it perhaps be that msmtp sits and (ultimately) waits for a terminating character such as CR/LF or EOF ? (I am unfamiliar with what the piped stream actually sends to the command)
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8036
Re: sending email not working
« Reply #18 on: June 14, 2024, 08:35:27 am »
I am also not familiar with the details of such piping as shown by your example Remy but could it perhaps be that msmtp sits and (ultimately) waits for a terminating character such as CR/LF or EOF ? (I am unfamiliar with what the piped stream actually sends to the command)

Or a dot at the start of a line, possibly by itself. That was "the UNIX way" in days of yore.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

rvk

  • Hero Member
  • *****
  • Posts: 6585
Re: sending email not working
« Reply #19 on: June 14, 2024, 10:57:08 am »
Code: Pascal  [Select][+][-]
  1. sp.Executable := 'msmpt';
  2.  
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.
You did change the msmpt to msmtp, didn't you?  ;)

I did a quick test. There is no output so if you comment out the reading of the non-existing output, it will go through.

Code: Pascal  [Select][+][-]
  1. program mailtest;
  2. {$MODE OBJFPC}{$H+}
  3. uses classes, sysutils, process;
  4.  
  5. const
  6.   frommail = 'me@meme.com';
  7.   tomail = 'me@meme.com';
  8.  
  9. function foo(): Boolean;
  10. var
  11.   sp: TProcess;
  12.   L: TStringList;
  13. begin
  14.   L := TStringList.Create;
  15.   sp := TProcess.Create(nil);
  16.   try
  17.     sp.Options := [poUsePipes];
  18.     sp.Executable := 'msmtp';
  19.     sp.Parameters.Add('--from=' + frommail);
  20.     sp.Parameters.Add(tomail);
  21.     sp.Execute;
  22.     L.Text := 'Hello World';
  23.     L.SaveToStream(sp.Input);
  24.  
  25.     {
  26.     L.Clear;
  27.     L.LoadFromStream(sp.Output);
  28.     WriteLn(L.Text);
  29.     }
  30.  
  31.     writeln('Exit status: ', sp.exitstatus);
  32.     writeln('Exit code: ', sp.exitcode);
  33.  
  34.   finally
  35.     sp.free;
  36.     L.free;
  37.   end;
  38.   Result := true;
  39. end;
  40.  
  41.  
  42. begin
  43.   writeln('Start');
  44.   writeln('Date = ', {$i %DATE%});
  45.   writeln('FPC target = ', {$i %FPCTARGET%});
  46.   writeln('FPC target CPU = ', {$i %FPCTARGETCPU%});
  47.   writeln('FPC target OS = ', {$i %FPCTARGETOS%});
  48.   writeln('FPC version = ', {$i %FPCVERSION%});
  49.  
  50.   foo();
  51.  
  52. end.

Quote
Start
Date = 2024/06/14
FPC target = aarch64
FPC target CPU = aarch64
FPC target OS = Linux
FPC version = 3.3.1
Exit status: -1
Exit code: 0

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1430
    • Lebeau Software
Re: sending email not working
« Reply #20 on: June 14, 2024, 05:57:25 pm »
Code: Pascal  [Select][+][-]
  1. sp.Executable := 'msmpt';
You did change the msmpt to msmtp, didn't you?  ;)

 %) thanks, I fixed it in my earlier example.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 460
  • Programming is FUN only when it works :)
    • Cool Technology
Re: sending email not working
« Reply #21 on: June 18, 2024, 02:51:43 pm »
Sorry, I couldn't get back right away.

That's what I end up doing. Commented out the output part of the code and it went straight through.

What doesn't make sense is that after reading your comments about not receiving input characters or ending the inputstream with dots or CR/LF, well by the time the program reached the outputstream pause the email has already be sent and received.

just thought i should let them no...

Thank you for your answers and suggestions.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8036
Re: sending email not working
« Reply #22 on: June 18, 2024, 03:14:11 pm »
What doesn't make sense is that after reading your comments about not receiving input characters or ending the inputstream with dots or CR/LF, well by the time the program reached the outputstream pause the email has already be sent and received.

All that indicates is that the mailer is not actually waiting for a . terminator or for further input. I wouldn't generally expect something in that position to be concerned about the lifetime of the program that's called it, which is what your final fix changed.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1430
    • Lebeau Software
Re: sending email not working
« Reply #23 on: June 18, 2024, 08:20:02 pm »
What doesn't make sense is that after reading your comments about not receiving input characters or ending the inputstream with dots or CR/LF, well by the time the program reached the outputstream pause the email has already be sent and received.

It does make sense, if you take into account that when using poUsePipes, TProcess.Execute() closes its end of the pipes it creates before exiting back to the caller.  So, when msmtp has read in all of the data from the stdin pipe, and the pipe has been closed, it knows there is no more data to read in and can send what data it did read.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018