Solved

Send Email Addresses in ShellExecute

Posted on 1998-02-28
6
396 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 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