Re: Sending email from a Delphi application



DIKonsult wrote:
look simple enough, thanks a lot.
I presume that if I need a bodytext I write:
Mail := 'mailto:e.brown@xxxxxxxxxxx' + '?subject=test'+'?Body='This is a body text in my mail';

Too many question marks. The format is just like a regular HTTP URL. If you supply parameters, they are separated from the main URL by a question mark. Multiple parameters are separated by ampersands. So the string you're looking for is this:

'mailto:e.brown@xxxxxxxxxxx?subject=test&body=This+is+a+body+text+in+my+mail'

It's a URL, so parameter values should be URL-encoded.

or have I got it wrong?

Could you please explain to me whats actually happening with this call.

With that call, as with any ShellExecute call, the OS looks through the registry to find the application registered for the kind of string passed in. Usually, it finds a program based on the extension of the file name, but in this case, it finds the application associated with the "mailto:"; prefix.

The registry contains information for the OS regarding how it's supposed to invoke the associated program. It's probably set up to start the program with the given "mailto:"; string as a command-line parameter.

Not all programs support "mailto" parameters. Most will accept the basic "mailto:address@xxxxxxxxxxx"; string to initiate an e-mail to the given address, but some will not accept any additional parameters after the address, such as the "subject" and "body" values. Other e-mail programs will accept some parameters but not others -- they might understand "subject" and "body," but not "cc" or "reply-to."

Programs started with ShellExecute and "mailto:"; do not automatically send the e-mail. If they do anything at all, then merely display the e-mail composition screen, just as though a user had started the message manually. With MAPI, you can instruct the program to send the e-mail. Some programs might not send it immediately, though; they might require the user's manual confirmation since the feature has been abused in the past to generate spam and propagate e-mail worms.

MAPI is a much more reliable method than ShellExecute. Not all programs support MAPI, and those that do don't always support it fully, so in that sense it's no better then ShellExecute. But with MAPI, when a program doesn't support some aspect of it, your program will be able to detect that by the error codes returned by the MAPI functions. With ShellExecute, you get almost no feedback. The only response your program gets is whether the OS was able to start running the associated application, not the level of success the application had.

--
Rob
.


Quantcast