Silent mailto with ShellExecute or alternative

I can do a mailto by doing
easily setting the email to address, subject and body.

What I want to do is have a silent send to the email cleint outbox and not open the email at all. Can this be done with ShellExecute?

If not, is there another reliable way? This is for an inhouse app where outlook and outlook express are the email client so it doesn't have to be more rebust though I would ideally like not to have the email cleint as a prerequisite  

Thanks, Tom.

ps. Compiler : D5.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
Incorporate a SMTP component in your app, such as TidSMTP from the Indy suite.
Then all you will have to do is ask your user to enter their email host, account and password
when installing your app.
Martyn SpencerSoftware Developer / Linux System Administrator / Managing DirectorCommented:
Or you could use the MAPI interface, which is supported in D5 - look at MAPI.pas and see if this helps.
call this with Showdialog = false

uses mapi;

procedure SendMailDialog(Recip, Subject, Body, Attach : string; ShowDialog : boolean);
  mapiMsg : TMapiMessage;
  // mapiRecip : TMapiRecipDesc;
  smapiRecip : TMapiRecipDesc;
  mapiFileDetail : TMapiFileDesc;
  //r : Integer;
  AFile : String;
  FillChar(mapiMsg, SizeOf(mapiMsg), 0);
  // FillChar(mapiRecip, SizeOf(mapiRecip), 0);
  FillChar(smapiRecip, SizeOf(smapiRecip), 0);
  FillChar(mapiFileDetail, SizeOf(mapiFileDetail), 0);

  {mapiRecip.ulRecipClass := MAPI_ORIG;
  mapiRecip.lpszName := 'paks';
  mapiRecip.lpszAddress := 'emailaddr';}

  smapiRecip.ulRecipClass := MAPI_TO;
  smapiRecip.lpszName := '';
  smapiRecip.lpszAddress := PChar(Recip);

  mapiFileDetail.lpszPathName := PChar(Attach);
  AFile := ExtractFilename(Attach);
  mapiFileDetail.lpszFileName := PChar(AFile);

  mapiMsg.lpszSubject := PChar(Subject);
  mapiMsg.lpszNoteText := PChar(Body);
  // mapiMsg.lpOriginator := @mapiRecip;
  mapiMsg.nRecipCount := 1;
  mapiMsg.lpRecips := @smapiRecip;
  mapiMsg.nFileCount := 1;
  mapiMsg.lpFiles := @mapiFileDetail;
  if ShowDialog then
    MapiSendMail(0, 0, mapiMsg, MAPI_LOGON_UI+MAPI_DIALOG, 0)
    MapiSendMail(0, 0, mapiMsg, 0, 0);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

boardtcAuthor Commented:
Thanks for your comments guys. Eddie, if I use the Indy component will it contact the smtp server directly and bypas the email client sent box? I need a record kept in the sent box. If not, perhaps the mapi solution is the way forward though I am going to be using Indy also for some ftping. so if it can do the former, great.

Thanks a lot, Tom.
If you want a copy in the "sent" folder then you'll have to use MAPI.  (My routine above works well, even lets you have attachments)

Or use the free TEmail component, available thru  Or ask me, and  I'll send it to you.
How can you avoid having the email client as a prerequisite AND expect the email client to save a copy of the sent message?

I don't think Outlook Express adequately supports MAPI, but Outlook supports both simple MAPI and Extended MAPI.  Simple MAPI is often used by scripted viruses, so Microsoft has made simple MAPI problematic.  You'll really want to use Extended MAPI if your system administrators have applied certain security patchs to Exchange that result in popup warnings that a program is accessing Exchange "on your (user's) behalf" or accessing the Global Address List, etc.  

 If you go the extended MAPI approach, I recommend EasyMAPI (  which costs $49 for a single developer without source code or $199 with source.  They have a trial version with examples.
We bought the site license for $499 with source ($199 without) because we have several developers using it.  There is still a learning curve with EasyMAPI, but the examples will show you how to do emails and a lot more. Also, you will have the choice whether to save a copy in the user's sent folder if you automatically send email.  If you show the email dialog, EasyMAPI will respect the user's preference of saving / not saving messages in the sent folder.  Incidentally, Outlook does not have to be running, but if it isn't you can get into issues if multiple profiles are present or if the default profile is password protected.

Another resource is www.IMIBO.COM.  You'll need to register ($49 and up) to get the source code to their examples.  Incidentally, I spent weeks on Extended MAPI (including examples from IMIBO) without making a dent in it until I discovered EasyMAPI.   Try EasyMAPI first.

>>How can you avoid having the email client as a prerequisite AND expect the email client to save a copy of the sent message?

I don't think that is what he is asking.  I think he just wants Outlook to go ahead and send the e-mail (quietly) without any user response or notification.  I do this in many of my applications.  Both solutions that I offered, will do just that.
>>I don't think that is what he is asking.

In his original question, tomcorcoran stated "though I would ideally like not to have the email cleint as a prerequisite".  He replied to EddieShipman's SMTP approach with " I need a record kept in the sent box. ".  

>> "send the e-mail (quietly) without user response or notification".

I do this in numerous applications as well, and simple MAPI isn't suitable anymore (depending on administratively controlled security settings).  Originally, I was using simple MAPI (TEmail and OfficePartner) and it worked fine, but we "upgraded" to Outlook 2002/XP, which included default security options that caused popup messages that were unacceptable.  These security measures are also part of an update for Outlook 2000 (and probably other versions) that could be an issue.

If tomcorcoran wants to save a copy in his sent mail, and his environment includes the security issues I've described, then Extended MAPI may be the best and possibly only approach.  
You are correct, CQ.  I was just going by his opening line..

>>What I want to do is have a silent send to the email cleint outbox and not open the email at all

I have one installation with about 100 users on a very secure (State Government) Novell network running XP and Groupwise.  Looking back at my source, I see that I used the TEmail component, modified slightly.  Tom, feel free to try it.

Component source code    (case-sensitive)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.