How to launch email program

Posted on 2005-04-12
Last Modified: 2010-04-05
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.
Question by:HorridMan
    LVL 11

    Expert Comment

    This is what Simple MAPI is for.
    Try the Jedi Code library
    It has a class to access Simple Mapi.

    Alternatively use the JVCL (includes JCL)
    It has a component on top of the JCL class.
    LVL 17

    Accepted Solution


    Try this:

    uses ShellApi;

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

    // usage
    procedure TForm1.Button1Click(Sender: TObject);
      LaunchEMail('', 'Hello');

    Regards, Geo
    LVL 1

    Expert Comment

    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! ;)

    Justin Willis.
    LVL 17

    Expert Comment

    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
    LVL 1

    Expert Comment

    wow, thanks, i didn't realize there was that much difference.

    thanks very much for highlighting those.


    Expert Comment

    Hello HorridMan


    procedure TForm1.Button1Click(Sender: TObject);
      strEmail, strSubject, strBody, Param: string;
      strEmail := '';
      strSubject := 'Your Subject';
      strBody := 'Your Message Text';

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

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

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    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…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now