Mega Code Archive

 
Categories / Delphi / Activex OLE
 

How to send an email with attachments by shellexecute to outlook express

Title: How to send an email with attachments by shellexecute 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;