본문 바로가기
Application/Delphi Lecture

아웃룩으로 메일 보내자..

by 현이빈이 2008. 8. 13.
반응형
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;
반응형