Silent mailto with ShellExecute or alternative

Posted on 2003-12-02
Last Modified: 2012-06-21
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.

Question by:tomcorcoran
LVL 26

Expert Comment

ID: 9860151
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.

Expert Comment

ID: 9860425
Or you could use the MAPI interface, which is supported in D5 - look at MAPI.pas and see if this helps.

Accepted Solution

roknjohn earned 50 total points
ID: 9860891
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);
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 9862352
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.

Expert Comment

ID: 9862717
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.

Assisted Solution

cqhall earned 25 total points
ID: 9867082
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.


Expert Comment

ID: 9867124
>>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.

Expert Comment

ID: 9867708
>>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.  

Expert Comment

ID: 9867963
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)

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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