¿Cómo puedo enviar un mensaje a través de un cliente de correo electrónico específico?

I have an application which is required to send a formatted message and an address to an email client (e.g. Lotus Notes, Outlook, etc. - preferably the former). The client should then mail that message in the background without any intervention (i.e. no one should have to press on send in the client).

I have the message, I have the address and I know how to pick a default email client.

How do I send the preformatted message and address (I'm guessing some MAIL:TO) and have the client send the message automatically?

The application is in C++ and Qt. I'll probably require some API of the client to be called. Do they expose these?

preguntado el 24 de agosto de 12 a las 07:08

I'm interested to see how this is done -

Why does a specified client need to send the message, as opposed to just sending the message from your app? Qt allows you to do this: documentos -

Official reasons etc. etc. Bureaucratic stuff. -

@pyCthon: you can track progress of a question by clicking the star button on the left of the answer. -

1 Respuestas

This is somewhat platform dependent, and can be handled in one of two ways: there is a mail server process, to which you connect (using a socket); or, you pipe the output to a mail client (mail or mailx under Unix). Piping to the mail client is usually simpler, but I'm not sure Windows machines have one readily available. (You say you have a default email client. In what form? If it's a URL, you'll need to use the socket; if it's the name of a local program, the pipe.)

In both cases, you'll probably want to create a streambuf to handle the output, in order to use all of the formatting possibilities of std::ostream.

If you want to do it in background, the surest way is to create a separate process: write the data to a file, then use system to execute the mail client and delete the file when finished (a small batch script). Alternatively, you can do it in a separate thread, if you're sure that your process will not be killed before the mail has been sent.

Respondido 24 ago 12, 09:08

I have the message to be sent, and I'll get an address to send it to, and a from address of course. My next course would be t identify the default application for mail in my system ( Like when I right click on file and click on "Zip and email this file", it automatically opens the default client), then automate the filling out of the relevant fields, and the send. So it'll be a local program on the system, I guess. I got the part about the streambuf. Would you develop the last point, please? And any thing else I should watch out for. I'm rather inexperienced. - user1173240

@user1173240 The last point is simply about how you do something "in background". Historically, in background meant a separate process, which meant fork y exec on older Unix, and spawn under Windows (and posix_spawn under modern Unix). You can get largely the same effect by starting a separate thread in your process; this is simpler, pero if your process exits (e.g. by returning from main), all of its threads will be killed, whether they've finished their job or not. If you fork, the child process will continue. - james kanze

@user1173240 Of course, if you want a separate process, you can also write all of the data to disk, and invoke system. Say with something like system( "(mailx < tmpfile ; rm tmpfile)&" ). This may be the simplest solution. - james kanze

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.