Solved

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

Posted on 2004-08-11
5
235 Views
Last Modified: 2010-04-05
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;
begin
  Try
    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;
    ShellExecute(Application.Handle,'open',PChar(Buffer),nil,nil,SW_Normal);
  Except
  end;
end;

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.
0
Comment
Question by:Delphiwizard
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 125 total points
ID: 11772428
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...
0
 
LVL 6

Accepted Solution

by:
pritaeas earned 125 total points
ID: 11773103
Hier nog eentje...

you could try to send %26 instead, this also works in URL's, like %20 for a space.
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 11773129
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...
0
 

Author Comment

by:Delphiwizard
ID: 11773747
And the function is born.

Bedankt allebei. Punten worden verdeeld. Beiden 125.

Function OmzettenAmpersand(Const E : string) : String;
begin
  Result := E;
  Result := StringReplace(result, '&', '%26', [rfReplaceAll]);
end;
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11773810
why not just:
  Result := StringReplace(E, '&', '%26', [rfReplaceAll]);

:-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question