Solved

Send Email Addresses in ShellExecute

Posted on 1998-02-28
6
397 Views
Last Modified: 2010-04-06
I use teh shellExcute statement to open the default email package on the user's system and pass the email address as a pchar.

var
 email:pchar;
begin
email := 'mailto:' + email.text +#0;
shellexecute(0, 'open', pchar(@email[1]), nil, nil, SW_SHOWNORMAL);
end;

Now I want to execute the email program and add several email addresses.  I have all of the email addresses in a listbox.  Here's the code I have so far;

for i := 0 to listbox1.items.count-1 do
 begin
  email := email + i;
 end

shellexecute(0, 'open', pchar(@email[1]), nil, nil, SW_SHOWNORMAL);

This doesn't work, so I'd like to know what the problem is and to make sure this works on all email programs that accept the mailto parameter.
0
Comment
Question by:d4jaj1
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 20 total points
ID: 1359913
Hi d4jaj1,

I believe the code above is not a real copy of a working program isn't it ? The email var must be string, not PChar, right ?

Anyway, I think it's not the main problem, but the second piece of code is very strange !!

You're concatenating string with integer (i) ?!?!?!

I'll assume that you're trying to join the e-mail addresses in the loop setting the email var, right ?

So, the problem must be a missing comma between the addresses !
Try smth like this:

      for i := 0 to ListBox1.Items.Count-1 do
              email := email + ListBox1.Items[i] + ',';

IMPORTANT: You must delete the LAST comma of the string before calling ShellExecute !

IHTH

0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1359914
Nope, that doesn't compile.  Here's what I have.

var
 email:pchar;
 i: integer;
begin
for i := 0 to ListBox1.Items.Count-1 do
  email := email + ListBox1.Items[i] + ',';

shellexecute(0, 'open', pchar(@email[1]), nil, nil, SW_SHOWNORMAL);

I get an error stating incompatible types, pchar and string.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1359915
Ok.
This is the complete working code. I compiled it and sent e-mail with it. Just copy and paste:

procedure TForm1.Button1Click(Sender: TObject);
var
      email:string;
      i: integer;
begin
      email := 'mailto:';
      for i := 0 to ListBox1.Items.Count-1 do
            email := email + ListBox1.Items[i] + ',';
      Delete(email,Length(email),1);
      shellexecute(0, 'open', PChar(email), nil, nil, SW_SHOWNORMAL);
end;

IHTH,
Itamar
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:d4jaj1
ID: 1359916
Thanks,

Don't know why O was tring to assign a value to a pchar.  Anyway, it works just fine.  I was wondering (if you don't mind), what email program you were using.  I'm trying to make sure the "," will work for each mail progem.  I use Outlook, but a comma can only separate 2 email addresses if you select the option first.
0
 
LVL 3

Author Comment

by:d4jaj1
ID: 1359917
For got to grade it.
0
 
LVL 4

Expert Comment

by:itamar
ID: 1359918
Hi d4,

I tried with OutLook and 2 addresses too <g>, but I can try with Netscape and perhaps Eudora. Just give me more time.

Bye,
Itamar
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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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