Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

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.

2 Solutions
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 SpencerConsultantCommented:
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);

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 www.torry.net.  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 (www.rapware.com)  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
http://www.jcent.com/jcEmail.zip    (case-sensitive)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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