精品学习网->精美文摘

上一篇    全部文章


Delhpi调用outlook发送电子邮件

uses  Mapi,ShellApi,ComObj,Outlook2000,

procedure  TForm1.BitBtn2Click(Sender:  TObject);
const
    olMailItem  =  0;
var
    Outlook:  OleVariant;
    vMailItem,Recipient:  variant;
    h:  HWND;
begin
        h  :=  FindWindow(nil,  'Microsoft  Outlook');
        if  h=0  then    shellexecute(handle,'open','OUTLOOK.EXE',nil,nil,SW_SHOWNORMAL);
              try
                    Outlook  :=  CreateOleObject('Outlook.Application');

              except
                    Outlook  :=  GetActiveOleObject('Outlook.Application');
              end;
              vMailItem  :=  Outlook.CreateItem(olMailItem);
              Recipient:=vMailItem.Recipients.Add('xxx@xxx.net');    
              Recipient.Type:=olTo;
          //添加类型为CC(抄送)的收件人
              Recipient:=vMailItem.Recipients.Add('xxx@xxx.net');
              Recipient.Type:=olCc;
          //添加类型为BCC(暗送)的收件人
              Recipient:=vMailItem.Recipients.Add('xxx@xxx.net');
              Recipient.Type:=olBCC;
//              vMailItem.Recipients.Add('xxx@xxx.net');
              vMailItem.Subject  :='test  email';
//              vMailItem.Body  :=  '测试文档';
              vMailItem.BodyFormat:=2;
              vMailItem.HTMLBody:='

测试文档

';
//              vMailItem.Attachments.Add('C:\1.pdf');
              vMailItem.Send;
              VarClear(Outlook);
end;

FALSE

     返回顶部
Delhpi调用outlook发送电子邮件