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

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?
0
cosminm
Asked:
cosminm
  • 4
  • 3
  • 2
  • +1
1 Solution
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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
 
cosminmAuthor Commented:
Hope it works, seems to be a perfect solution :)
Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now