whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

49 Visitors Online


 
...send an email with attachments by shellexecute to outlook express?
Autor: Guest
Homepage: http://kingron.delphibbs.com
[ Print tip ]  

Tip Rating (37):  
     


{
  Shellexecute(Handle,'open','mailto:aaaa@bbb.com?subject&body=body
  text&CC=aaaa&bcc=dddd&attach=FileName',nil,nil,SW_SHOW)
  only works with outlook, not for outlook express,
  but the method below can send attachment to outlook express
}

uses
  
ComObj;

procedure SendMail(Subject, Body, RecvAddress : string; Attachs : array of string);
var
  
MM, MS : Variant;
  i : integer;
begin
  
MS := CreateOleObject('MSMAPI.MAPISession');
  try
    
MM := CreateOleObject('MSMAPI.MAPIMessages');
    try
      
MS.DownLoadMail := False;
      MS.NewSession := False;
      MS.LogonUI := True;
      MS.SignOn;
      MM.SessionID := MS.SessionID;

      MM.Compose;

      MM.RecipIndex := 0;
      MM.RecipAddress := RecvAddress;
      MM.MsgSubject := Subject;
      MM.MsgNoteText := Body;

      for i := Low(Attachs) to High(Attachs) do
      begin
        
MM.AttachmentIndex := i;
        MM.AttachmentPathName := Attachs[i];
      end;
      MM.Send(True);
      MS.SignOff;
    finally
      
VarClear(MS);
    end;
  finally
    
VarClear(MM);
  end;
end;

procedure TForm1.FormCreate(Sender : TObject);
begin
  
SendMail('Subject', 'Body'#13#10'Second', 'BillGates@Microsoft.com',
    ['C:\Winnt\explorer.exe', 'C:\winnt\win.ini']);
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners