?
Solved

Send Email Addresses in ShellExecute

Posted on 1998-02-28
6
Medium Priority
?
403 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
[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
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
itamar earned 80 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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