我做的程序里正好有个调用outlook发送html格式的邮件的例子,
希望对你有帮助!
procedure TPPMS120.sptnSendClick(Sender: TObject);
const olMailItem = 0;
var Outlook,MailItem,Recipient: variant;
strFilename,strTemp,strTempDir:string;
strlstAddr:Tstringlist;
i:integer;
begin
try
Outlook := CreateOleObject('Outlook.Application');
except
Outlook := GetActiveOleObject('Outlook.Application');
end;
MailItem := Outlook.CreateItem(olMailItem);
strTempDir:='C:\temp'+ formatdatetime('YYYYMMDDHHMMSS',Now);
CreateDir(strTempDir);
strlstAddr:=Tstringlist.Create;
try
GetAddrList('TO',strlstAddr);
for i:=0 to strlstAddr.Count-1 do
begin
Recipient:=MailItem.Recipients.Add(strlstAddr[i]);
Recipient.type:=olTO;
if not Recipient.resolve then
break;
end;
GetAddrList('CC',strlstAddr);
for i:=0 to strlstAddr.Count-1 do
begin
Recipient:=MailItem.Recipients.Add(strlstAddr[i]);
Recipient.type:=olCC;
if not Recipient.resolve then
break;
end;
MailItem.Subject :='Booking result as of '+strFileName;
GetMailBodyHtml(strTemp);
MailItem.htmlBody :=strTemp;
MakeAttachFile(strTempDir+'\'+strFileName+'.xls');
MailItem.Attachments.Add(strTempDir+'\'+strFileName+'.xls');
//mailitem.display;
mailitem.send;
finally
strlstAddr.free;
MailItem:=Unassigned;
Recipient:=Unassigned;
//outlook.quit;
outlook:=Unassigned;
DeleteTempDir(strTempDir,strFileName);
end;
end;
希望对你有帮助!
procedure TPPMS120.sptnSendClick(Sender: TObject);
const olMailItem = 0;
var Outlook,MailItem,Recipient: variant;
strFilename,strTemp,strTempDir:string;
strlstAddr:Tstringlist;
i:integer;
begin
try
Outlook := CreateOleObject('Outlook.Application');
except
Outlook := GetActiveOleObject('Outlook.Application');
end;
MailItem := Outlook.CreateItem(olMailItem);
strTempDir:='C:\temp'+ formatdatetime('YYYYMMDDHHMMSS',Now);
CreateDir(strTempDir);
strlstAddr:=Tstringlist.Create;
try
GetAddrList('TO',strlstAddr);
for i:=0 to strlstAddr.Count-1 do
begin
Recipient:=MailItem.Recipients.Add(strlstAddr[i]);
Recipient.type:=olTO;
if not Recipient.resolve then
break;
end;
GetAddrList('CC',strlstAddr);
for i:=0 to strlstAddr.Count-1 do
begin
Recipient:=MailItem.Recipients.Add(strlstAddr[i]);
Recipient.type:=olCC;
if not Recipient.resolve then
break;
end;
MailItem.Subject :='Booking result as of '+strFileName;
GetMailBodyHtml(strTemp);
MailItem.htmlBody :=strTemp;
MakeAttachFile(strTempDir+'\'+strFileName+'.xls');
MailItem.Attachments.Add(strTempDir+'\'+strFileName+'.xls');
//mailitem.display;
mailitem.send;
finally
strlstAddr.free;
MailItem:=Unassigned;
Recipient:=Unassigned;
//outlook.quit;
outlook:=Unassigned;
DeleteTempDir(strTempDir,strFileName);
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货