Solved

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

Posted on 2004-08-11
5
230 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now