1.定义//mail信息结构
type
TMailInfo = record
strUID, strPWD, strHost:string; //SMTP用户ID , SMTP用户密码 , SMTP主机
iPort:Integer; //SMTP端口
strSubject:string; //邮件主题
slBody:TStringList; //邮件内容
strFromAddr, strToAddr:string; //发件人 , 收件人
sAtta:TStringList; //附件
bView:Boolean;
strMailCC: string; //抄送
end;
2.定义Mailp:TMailInfo;
3.procedure SendMailByOutlook;
var
MI: MailItem;
begin
Try
OutlookApplication1.Connect; //直接连接,OUTLOOK已经打开才有用
MI := OutlookApplication1.CreateItem(olMailItem) as MailItem;
MI.CC := Mailp.strMailCC; //抄送
MI.Recipients.Add(Mailp.strToAddr);
MI.Subject := Mailp.strSubject;
if Mailp.slBody.Text = '' then
MI.HTMLBody := '<H1>Dear</H1> xxok2001:'
else
MI.HTMLBody := Mailp.slBody.Text;
if Mailp.sAtta.Count <> 0 then //HF 零时代码
MI.Attachments.Add(Mailp.sAtta[0],EmptyParam,EmptyParam,EmptyParam);
MI.Display(True);
except
Showmessage('没有安装或不能启动OutLook!')
end;
end;
4.需要引用的单元
ComObj, OleServer, Outlook2000, OutlookXP ;