this might be a walkaround:
timeout 3 bash -c "echo "body" | mailx -S sendwait -s "title" firstname.lastname@example.org
manul: When sending a message, wait until the mail transfer agent exits before accepting further commands. If the mail transfer agent returns a non-zero exit status, the exit status of mailx will also be non-zero.
My thinking: so sendwait is to ask mailx to do email sending in only one process instead of starting a child process. I think only in this way the "timeout" control is meaningful or else "timeout" is only checking the wrapping program. is this correct?
2. the command works but it is better to use
timeout 3 bash -c "echo 'body' | mailx -S sendwait -s 'title' email@example.com
the thing I dont quit understand is how does the double-quote inside double-quote work in this command?
I can only find this in "man bash":
-c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.
Can anybody explain more on this?
3. I use bash -c because there is pipe inside the mail command. Is this the only solution for piping?