Solved

Calling default mail program

Posted on 1998-10-26
14
137 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

19 Experts available now in Live!

Get 1:1 Help Now