Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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