Solved

Calling default mail program

Posted on 1998-10-26
14
140 Views
Last Modified: 2010-04-06
I need to call the default mail program from my application. At the same time, I'd like to submit text to the Subject property and Message property of the new mail.

This is for a 'Recommend this program to your best friend'-feature. The user clicks a Recommend button, and a new mail is created with the subject 'Recommended software: xyz' and the text 'The software xyz is freeware. You can download it from: www.abc.com'.
The user only has to write the recipients mail address and press the send button of his/her default mail program.

Any help is appreciated!
Thanks in advance.
0
Comment
Question by:friberg
  • 9
  • 5
14 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344414
Hi friberg,

I latest learned about this one :


ShellExecute(0, 'open', 'mailto:xxx@xx.xx', 'subject', nil, SW_NORMAL);

But I don't know if a message body can directly be added.

I used to use MAPI, which is able to add a message body :

read about it all and use this freeware component at

http://torry.rimini.com/vcl/internet/temail2.zip

Regards, Zif.
0
 

Author Comment

by:friberg
ID: 1344415
Thanks ZifNab, but I need to call the standard mail program, not MAPI.

Maybe someone nows how to add a message as well with ShellExecute?


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344416
friberg,

MAPI is for talking to mapi compliant e-mail programs, like Outlook and Eudora. You send your e-mail with MAPI messages to the email program on the pc. So, with MAPI you normally call the default e-mail program. Look at the docs of the component I referred to.

you can even add your attachments directly!

Zif.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1344417
Hi friberg,

I did some research and found out how to add the body message :

procedure TForm1.Button1Click(Sender: TObject);
var
  TempUrl : string;
begin
  TempUrl:='mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';

ShellExecute(Application.Handle,'open',PChar(TempURL),nil,nil,SW_NORMAL);
end;

ps. don't know if it will work for every e-mail client!
pps. I know it does for outlook, and netscape.
ppps. As I said, with MAPI you can already attacht the file and all the rest. And even send it! ShellExecute just opens a new email for you and fills in some stuff.
0
 

Author Comment

by:friberg
ID: 1344418
ZifNab,

Although I use Outlook Express, the component gave me the message 'MAPI services are not available on this system'.


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344419
Forgot something : if you want to use shellexecute, you need to add 'shellapi' to the uses clause.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344420
Hi friberg, I'm sorry to say that I made a mistake about MAPI. MAPI compliant systems are : Eudora, MS Exchange and other which I don't know of. Outlook Express isn't one of them. Sorry. Zif.
0
 

Author Comment

by:friberg
ID: 1344421
I need a solution that will work with IE4 and Netscape users as well (without having extra mail readers installed).
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344422
As I said : ShellExecute works for IE4 (=Outlook) and NetScape,

Try it out!

 Zif.
0
 

Author Comment

by:friberg
ID: 1344423
I have, but it won't let me add any text, only recipient and subject. Since it's a 'tell your friend about this program' feature, I don't know the recipient, only a subject, eg 'my program - recommended'. I want to put a link to my program in the text field, not in the subject field.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344424
Hi friberg,

I used this string :

'mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';

in this

procedure TForm1.Button1Click(Sender: TObject);
var
  TempUrl : string;
begin
  TempUrl:='mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';


ShellExecute(Application.Handle,'open',PChar(TempURL),nil,nil,SW_NORMAL);
end;

with D3.02 and IE4 and Outlook Express

And it works perfectly :

It opens a mail and adds these values :

To : Tom.Deprez@village.uunet.be
Subject : Your subject
Body : your body

Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344425
Hi friberg,

I used this string :

'mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';

in this

procedure TForm1.Button1Click(Sender: TObject);
var
  TempUrl : string;
begin
  TempUrl:='mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';


ShellExecute(Application.Handle,'open',PChar(TempURL),nil,nil,SW_NORMAL);
end;

with D3.02 and IE4 and Outlook Express

And it works perfectly :

It opens a mail and adds these values :

To : Tom.Deprez@village.uunet.be
Subject : Your subject
Body : test body

Regards, Zif.
0
 

Author Comment

by:friberg
ID: 1344426
Thanks, it works perfectly!
Please send it as an answer.
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1344427
Hi friberg,

Are you sure, because you said it didn't work?

To answer :

I used this string :

'mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';

in this

procedure TForm1.Button1Click(Sender: TObject);
var
  TempUrl : string;
begin
  TempUrl:='mailto:tom.deprez@village.uunet.be?subject=Your subject&body=test body';


ShellExecute(Application.Handle,'open',PChar(TempURL),nil,nil,SW_NORMAL);
end;

with D3.02 and IE4 and Outlook Express

And it works perfectly :

It opens a mail and adds these values :

To : Tom.Deprez@village.uunet.be
Subject : Your subject
Body : test body

Regards, Zif.

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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 99
Dynamically Created Query 3 62
Installshield for Embarcadero EX 10.1 Berlin 4 60
Breakpoint doesn't stop in my variable 3 30
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…

830 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