...send an e-mail through Outlook?

Author: Thomas Stutz

Category: Objects/ActiveX

uses
  
ComObj;

procedure TForm1.Button16Click(Sender: TObject);
const
  
olMailItem = 0;
  olByValue = 1;
var
  
OutlookApp, MailItem, MyAttachments: OLEVariant;
begin
  try
    
OutlookApp := GetActiveOleObject('Outlook.Application');
  except
    
OutlookApp := CreateOleObject('Outlook.Application');
  end;
  try
    
MailItem := OutlookApp.CreateItem(olMailItem);
    MailItem.Recipients.Add('YourMailAddress@something.com');
    MailItem.Subject := 'Your Subject';
    MailItem.Body    := 'Your Message';
    myAttachments    := MailItem.Attachments;
    myAttachments.Add('C:\SomeFile.txt', olByValue, 1, 'Name of Attachment');
    MailItem.Send;
  finally
    
myAttachments := VarNull;
    OutlookApp    := VarNull;
  end;
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base