Executing an action (emailto)...

I want to email a message using my default mapi client (if exist!) using the command "emailto:name@server.com?Subject=etc" and to attach some files too. How can I do this?
cosminmAsked:
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.

intheCommented:
hi,
the easiest way is too use temail32 mapi component.
i sent it too you just leave your email address,it comes with demos etc...

Regards Barry


0
intheCommented:
note:
using the command shellexecute with
"emailto:name@server.com?Subject=etc"
you cannot send attachmenbts tat why i say to use mapi component.
if you have smtp componont you could use that also..

nmsmtp1.PostMessage.Attachments := list of filenames;
nmsmtp1.PostMessage.FromAdress := ...
nmsmtp1.PostMessage.ToAddress := ..
nmsmtp1.sendmail;
0
cosminmAuthor Commented:
I need to popup the "new" mail window (from the default mail program) with fields already filled (To, Subject, Attachements).
I found a component which do this but is not working proprely (is locking both the program and the new mail window) and is trying to send the message (I don't want this - I want to modify it first)
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

cosminmAuthor Commented:
Please give me a solution...
My mail is cosmin@cimec.ro
0
rwilson032697Commented:
This is so weird - I posted comments essentially containing the same information that Barry posted - but they are nowhere to be found!

Cheers,

Raymond.
0
ckanetaCommented:
use the shellexecute command to run the
default mail server. the following code
works

ShellExecute(0, nil,
         PChar('mailto:name@server.com?Subject=etc'), nil, nil, SW_NORMAL);
if you add ShellAPI to your uses clause
you can even populate all the fields
       cc,bcc,subject,body

i wrote some code to parse through just
such a string, so that it doesn't matter
in what order it all appears, but if you
want that, you'll have to wait until I
get back to work tomorrow.
hope this helps...
cjk
0
cosminmAuthor Commented:
Ok, but the attachements?
0
ckanetaCommented:
The easiest way to do the attachments, I
would say, is to do it manually
I have yet to find a way to add it in
programatically, but I suppose(not tried) that you could send the program
the WM_KeyDown with the appropriate
paramaters to simulate keyboard entry


procedure Tmnfrm.parse(st:string);
var i,c,b,s,cnt,e:integer; tmp:string;
 begin
  i:=pos('?',st);
  c:=pos('cc=',st);        if c=0 then c:=pos('CC=',st);
  b:=pos('bcc=',st);       if b=0 then b:=pos('BCC=',st);
  s:=pos('subject=',st);   if s=0 then s:=pos('SUBJECT=',st);
  cnt:=pos('body=',st);    if cnt=0 then cnt:=pos('BODY=',st);
  if i=0 then add:=st else add:=copy(st,1,i-1);
  if (c<>0) and (c<>b+1) then begin
   tmp:=copy(st,c+3,length(st));   e:=pos('&',tmp);
   if e=0 then cc:=tmp else cc:=copy(tmp,1,e-1);
  end;
  if b<>0 then begin
   tmp:=copy(st,b+4,length(st));   e:=pos('&',tmp);
   if e=0 then bcc:=tmp else bcc:=copy(tmp,1,e-1);
  end;
  if s<>0 then begin
   tmp:=copy(st,s+8,length(st));   e:=pos('&',tmp);
   if e=0 then sub:=tmp else sub:=copy(tmp,1,e-1);
  end;
  if cnt<>0 then begin
   tmp:=copy(st,cnt+5,length(st));   e:=pos('&',tmp);
   if e=0 then con:=tmp else con:=copy(tmp,1,e-1);
  end;
 end;//}
0
intheCommented:
like i said you cant add attachment via shellexecute method..
doing it via keyboard isnt great idea(how to know where the attachments are(will they always be the same directory etc..)
the only ways is manually or use a component or use straight mapi api :


uses mapi;

function SendEMail(Handle :THandle;Mail :TStrings) :Cardinal;
 type
   TAttachAccessArray    = array [0..0] of TMapiFileDesc;
   PAttachAccessArray    = ^TAttachAccessArray;
 var
   MapiMessage : TMapiMessage;
   Receip      : TMapiRecipDesc;
   Attachments : PAttachAccessArray;
   AttachCount : Integer;
   i1          : integer;
   FileName    : String;

 begin
   fillChar(MapiMessage,SizeOf(MapiMessage),#0);
   Attachments:=nil;
   fillChar(Receip,SizeOf(Receip),#0);
   if Mail.Values['to']<>'' then
   begin
     Receip.ulReserved:=0;
     Receip.ulRecipClass:=MAPI_TO;
     Receip.lpszName:=StrNew(PChar(Mail.Values['to']));
     Receip.lpszAddress:=StrNew(PChar('SMTP:' + Mail.Values['to']));
     Receip.ulEIDSize:=0;
     MapiMessage.nRecipCount := 1;
     MapiMessage.lpRecips    := @Receip;
   end;
   AttachCount:=0;
   for i1:=0 to MaxInt do
   begin
     if Mail.Values['attachment'+inttostr(i1)]='' then break;
     inc(AttachCount);
   end;
   if AttachCount>0 then
   begin
     GetMem(Attachments,SizeOf(TMapiFileDesc)*AttachCount);
     for i1:=0 to AttachCount-1 do
     begin
       FileName:=Mail.Values['attachment'+inttostr(i1)];
       Attachments[i1].ulReserved    := 0;
       Attachments[i1].flFlags       := 0;
       Attachments[i1].nPosition     := ULONG($FFFFFFFF);
       Attachments[i1].lpszPathName  := StrNew(PChar(FileName));
       Attachments[i1].lpszFileName  := StrNew(PChar(ExtractFileName(FileName
 )));
       Attachments[i1].lpFileType    := nil;
     end;
     MapiMessage.nFileCount:=AttachCount;
     MapiMessage.lpFiles:=@Attachments^;
   end;

   if Mail.Values['subject']<>'' then MapiMessage.lpszSubject
 :=StrNew(PChar(Mail.Values['subject']));
   if Mail.Values['body']<>''    then MapiMessage.lpszNoteText
 :=StrNew(PChar(Mail.Values['body']));

   Result :=MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle<>0)
 or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);

   for i1:=0 to AttachCount-1 do
   begin
     strDispose(Attachments[i1].lpszPathName);
     strDispose(Attachments[i1].lpszFileName);
   end;

   if assigned(MapiMessage.lpszSubject)  then
 strDispose(MapiMessage.lpszSubject);
   if assigned(MapiMessage.lpszNoteText) then
 strDispose(MapiMessage.lpszNoteText);
   if assigned(Receip.lpszAddress)       then
 strDispose(Receip.lpszAddress);
   if assigned(Receip.lpszName)          then
 strDispose(Receip.lpszName);
 end;

procedure TForm1.Button1Click(Sender: TObject);
var
mail : tstringlist
begin
mail:=tstringlist.create;
mail.values['to']:='xyz@zz.com';
mail.values['subject']:='no subject';
mail.values['body']:='no subject';
mail.values['body']:='no subject';
mail.values['attachment0']:='c:\winnt\winnt256.bmp';
mail.values['attachment1']:='c:\winnt\winnt.bmp';
sendEMail(application.handle,mail);
mail.free;
end;
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
cosminmAuthor Commented:
Hope it works, seems to be a perfect solution :)
Thanks.
0
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
Delphi

From novice to tech pro — start learning today.