• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

How to launch email program

I want to launch an email program (whether Outlook or other) from my app. I need to pass a recipient email address to the email program, (and a subject line if possible). I guess WinExec is best, but I don't know what parameters to use.
Thanks
0
HorridMan
Asked:
HorridMan
1 Solution
 
robert_marquardtCommented:
This is what Simple MAPI is for.
Try the Jedi Code library http://jcl.sf.net
It has a class to access Simple Mapi.

Alternatively use the JVCL (includes JCL) http://jvcl.sf.net
It has a component on top of the JCL class.
0
 
geobulCommented:
Hi,

Try this:

uses ShellApi;

procedure LaunchEMail(const address, subject: string);
begin
  ShellExecute(0, 'open', PChar('mailto:'+address+'?subject='+subject), nil, nil, SW_SHOWNORMAL);
end;

// usage
procedure TForm1.Button1Click(Sender: TObject);
begin
  LaunchEMail('aaa@abv.bg', 'Hello');
end;

Regards, Geo
0
 
JustinWillisCommented:
Yes I think that is the best way, just wondering what ShellExecute does different that WinExec, i have always used WinExec before, what are the advantages of using ShellExecute instead?

If this is not a simple question/answer then don't worry about it! ;)

Regards,
Justin Willis.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
geobulCommented:
Hi Justin,

1. You can't simply call:
WinExec(PChar('mailto:'+address+'?subject='+subject), SW_SHOWNORMAL);

You'll have to find out the assosiated program first and then add the parameters after the program name. ShellExecute, on the other hand, does that for you and launches the default mail client, i.e. saves you some work (one FindExecutable API call). The same applies to all other nonexecutable filenames that have 'open' or 'print' assosiations to executables.

2. You may control the directory your process will start from.

3. You still may use an executable name directly passing parameters to it.

4. You may control whether the new process will have a parent window.

5. You may print a file directly just replacing 'open' with 'print':
ShellExecute(0, 'print', PChar('c:\test.doc'), nil, nil, SW_SHOWNORMAL);

Perhaps there is more I've missed above.

Regards, Geo
0
 
JustinWillisCommented:
wow, thanks, i didn't realize there was that much difference.

thanks very much for highlighting those.

Justin.
0
 
DTHLIEMCommented:
Hello HorridMan
--------------------------------------------

 uses
  ShellApi;


procedure TForm1.Button1Click(Sender: TObject);
var
  strEmail, strSubject, strBody, Param: string;
begin
  strEmail := 'user@host.com';
  strSubject := 'Your Subject';
  strBody := 'Your Message Text';

  Param := 'mailto:' + strEmail + '?subject=' + strSubject +
           '&Body=' + strBody;

  ShellExecute(Form1.Handle, 'open', PChar(Param), nil, nil, SW_SHOWNORMAL);
end;
 
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now