Solved

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

Posted on 2004-08-11
5
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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