I want in my HTML an href link which when clicked does a "mailto", like this:
<a href="mailto:donald@duck.org">Mail me</a>
Now, instead of the hard coded email address I want to return the address from a Delphi function. So I add a function like this (in a Unit named FormImprint):
function GetEMailAddress(AddrNo: Integer): String;
begin
Result := 'mailto:daisy@duck.org';
end;
The Pascal function seems to get called successfully, but instead of opening an empty email I see a blank page with nothing but the string "mailto:daisy@duck.org".
What do I have to do for the "mailto:" action to execute? Is my way of approaching this the best practice?
Thank you Bruno, but then the email address is visible in the HTML DOM as if it was hardcoded, which is not wanted. The email address should be obfuscated to prevent spam and therefore rertrieved through a function call, which e.g. gets the email address from a DB or from some kind of decryption. So the email address should be provided in the very moment when the user clicks the href. My approach of
basically already does what I want by means of that the pascal function is called. My problem is just that this does not trigger the email client program to popup and show a correctly pre-addressed email envelope.
When my pascal function returns "mailto:name@server" the browser opens a new empty page with the text "mailto:name@server". When I do
and my pascal function returns just "name@server", the email client pops up as desired but the TO address is set to "javascript:pas.FormImprint.GetEMailAddress(1)". I tried some other keyword bingo but to no avail so far.
Got it! The solution is to not use the HREF property at all (leave it empty) and instead in the OnClick of the linked TWebHTMLAnchor do an Application.Navigate('mailto:name@server');