TSendMail Action

If you’ve ever wondered how to use TSendMail action in ExtActns unit – drop it, it’s useless. I’ve had a few people complaining they don’t know how to set the Recipients and Subject set it – you can’t do it 🙂

Let’s look at the source code for the TSendMail.ExecuteTarget method:

First:

lpszSubject := nil;
lpszNoteText := PAnsiChar(AnsiString(Text.Text));
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;

and then:

MError := MapiSendMail(0, Application.Handle, MapiMessage,
    MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
if MError <> 0 then 
    MessageDlg(SSendError, mtError, [mbOK], 0);

Three problems with this code:

  1. First it has no support for Subject and Recipients/CC and related.
  2. If the user closes the “Send mail window” of his mail client, a message box will pop up – and you can’t do anything about it!
  3. The text is converted to ANSI so no Unicode support for you email.

The first problem can be solved rather simply by the VCL developers but I think it’s not top priority anyway.

For the second problem it should at least have been an event like OnMailResult with a Boolean that would say – MessageWasSent so that you, the developer would have the control of what you would do in case of failure/cancel.

Anyway, let’s hope the VCL gets cleaned up a bit in the next years and such controls are removed or updated to actually be useful to someone.

You May Also Like

About the Author: Alexandru Ciobanu

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.