Solved

Send Email Addresses in ShellExecute

Posted on 1998-02-28
6
394 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
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

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

9 Experts available now in Live!

Get 1:1 Help Now