Solved

Silent mailto with ShellExecute or alternative

Posted on 2003-12-02
9
1,370 Views
Last Modified: 2012-06-21
I can do a mailto by doing
 ShellExecute(0,'open',PChar(mailto:...),'','',SHOWNORMAL);
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.
.

0
Comment
Question by:tomcorcoran
9 Comments
 
LVL 26

Expert Comment

by:EddieShipman
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.
0
 
LVL 2

Expert Comment

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

Accepted Solution

by:
roknjohn earned 50 total points
ID: 9860891
call this with Showdialog = false

uses mapi;

procedure SendMailDialog(Recip, Subject, Body, Attach : string; ShowDialog : boolean);
var
  mapiMsg : TMapiMessage;
  // mapiRecip : TMapiRecipDesc;
  smapiRecip : TMapiRecipDesc;
  mapiFileDetail : TMapiFileDesc;
  //r : Integer;
  AFile : String;
begin
  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)
  else
    MapiSendMail(0, 0, mapiMsg, 0, 0);
end;
0
 

Author Comment

by:tomcorcoran
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:roknjohn
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 www.torry.net.  Or ask me, and  I'll send it to you.
0
 
LVL 2

Assisted Solution

by:cqhall
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 (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.

Chuck
0
 
LVL 1

Expert Comment

by:roknjohn
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.
0
 
LVL 2

Expert Comment

by:cqhall
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.  
0
 
LVL 1

Expert Comment

by:roknjohn
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
http://www.jcent.com/jcEmail.zip    (case-sensitive)
0

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

14 Experts available now in Live!

Get 1:1 Help Now