Solved

Calling default mail program

Posted on 1998-10-26
14
136 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

18 Experts available now in Live!

Get 1:1 Help Now