How to send a '&' in a Email subject via ShellExecute

How can I send a '&' in a Email subject via ShellExecute.
Now I'm using following code to send an Email with default Email-program (Outlook Express).

procedure TFRelatiegegevens.StuurEmailClick(Sender: TObject);
Var Buffer : String;
    Ontvanger,Onderwerp,EmailTekst : String;
    Ontvanger := IEmail.Text;        {message recipients email address}
    Onderwerp := 'E-mail van '+DM.TBedrijfsgegevens.FieldByName('Naam').AsString;   {message subject}
    Emailtekst:= 'Hallo '+DM.TRelaties.FieldByName('HeleNaam').AsString;
    Buffer    := 'mailto:'+Ontvanger+'?subject='+Onderwerp+'&body='+Emailtekst;

DM.TBedrijfsgegevens.FieldByName('Naam').AsString contains a '&'.
The subject is displaying only the part before the '&'. Everything behind it is lost.

How can I solve this? -> preferrably not changing the '&' :-)

Thanks Stef.
Stef MerlijnDeveloperAsked:
Who is Participating?
pritaeasSoftware EngineerCommented:
Hier nog eentje...

you could try to send %26 instead, this also works in URL's, like %20 for a space.
Wim ten BrinkSelf-employed developerCommented:
Hey, een nederlander. :-)

Have you tried changing the & into & ? Theoretically, the Mailto: tag is part of an URL, thus the whole thing is considered to be an URL. And with URL's, the & is seen as a separator between parameters. A quick StringReplace could change the & in your fields into & but it's not a great solution...
pritaeasSoftware EngineerCommented:
Oops, forgot. You can also sent the whole text between double quotes. This will only work of course if your text doesn't contain them...
Stef MerlijnDeveloperAuthor Commented:
And the function is born.

Bedankt allebei. Punten worden verdeeld. Beiden 125.

Function OmzettenAmpersand(Const E : string) : String;
  Result := E;
  Result := StringReplace(result, '&', '%26', [rfReplaceAll]);
Wim ten BrinkSelf-employed developerCommented:
why not just:
  Result := StringReplace(E, '&', '%26', [rfReplaceAll]);

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.