Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send Email Addresses in ShellExecute

Posted on 1998-02-28
6
Medium Priority
?
404 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

604 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