PDA

View Full Version : sendmail sentients



mdklatt
8/2/2007, 01:19 PM
I'm trying to use sendmail as the backend for sending e-mail from a C++ application using popen(), etc. How do I send an abort to sendmail if I encounter an error? It tries to send a message no matter what as soon as I call pclose().

I cannot believe I'm the first person to have this problem, but I'll be damned if I can find any documentation on it.

sooner_born_1960
8/2/2007, 01:27 PM
Do you mean an error in sending the mail? If not, don't call the sending routine until you're past any posibility of an error.

Penguin
8/2/2007, 01:35 PM
Bad cookies.

Reformat your hard drive.

mdklatt
8/2/2007, 01:39 PM
If not, don't call the sending routine until you're past any posibility of an error.

The error is in the sending routine itself while writing the message to sendmail with fwrite(). Can't I tell sendmail, "look, I know I told you to send this message, but now I've changed my mind"? From a command prompt, a Ctrl-C will do this. How I do that using a pipe?

TUSooner
8/2/2007, 01:40 PM
23?

Vaevictis
8/2/2007, 09:21 PM
Use the "RSET" command.

FWIW, http://www.faqs.org/rfcs/rfc821.html

I guess, of course, this is assuming you are using SMTP... (which you should) You want the '-bs' switch, if you're not already using it.

Vaevictis
8/2/2007, 09:34 PM
The error is in the sending routine itself while writing the message to sendmail with fwrite(). Can't I tell sendmail, "look, I know I told you to send this message, but now I've changed my mind"? From a command prompt, a Ctrl-C will do this. How I do that using a pipe?

And if this is the specific functionality you're looking for (as opposed to using SMTP like I previously posted)...

Well, control-C is interpreted by the console and sends a SIGINT to the process on stdin. To do this, you need to figure out the process id number and signal it with sigint.

This is pretty non-trivial if you used popen (which you said you did) because it doesn't give you any idea about what the pid is, and gives you no easy way to find out.

If this is really what you want to do, you're going to need to manually fork() (which does tell you the pid of the child process), and manually redirect stdin/stdout. This is pretty unpleasant to do, but you can find information on how to do it http://www.cs.uleth.ca/~holzmann/C/system/pipeforkexec.html

Probably easier using the technique here: http://db.ilug-bom.org.in/Documentation/lpg/node11.html

Once you know the pid, use the kill() function (probably in section 2 of the manual) to send the signal. For the list of available signals, probably look in section 7 of the manual.