关于html的问题比较复杂,不是三言两语可以解析清楚的,你可以参考我之前写的一个代码片断,能参考到多少东西我也不知道,还有别的不清楚的东西你可以搜索delphibbs的离线CHM。
procedure TMailReceiveThread.FillMail_Info(UIDL:string);
procedure FillAttachmentInfo;
var
i,index:Integer;
str,FileID:string;
Attachment:TIdAttachmentFile;
Mail_AttachmentInfo:TMail_AttachmentInfo;
begin
for i := 0 to FMessage.MessageParts.Count - 1 do
begin
if FMessage.MessageParts.PartType=mptText then
FMail_Info.Mail_Info_Content:=TIdText(FMessage.MessageParts).Body.Text
else
begin
Attachment:=TIdAttachmentFile(FMessage.MessageParts);
Mail_AttachmentInfo:=TMail_AttachmentInfo.Create;
if Attachment.FileName<>'' then
Mail_AttachmentInfo.AttachmentInfo_Name:=CheckTxt(Attachment.FileName)
else
Mail_AttachmentInfo.AttachmentInfo_Name:='unknown';
Mail_AttachmentInfo.Mail_AttachmentInfo_Content.LoadFromFile(Attachment.StoredPathName);
if FMessage.MessageParts.Items.Headers.IndexOfName('Content-ID')>=0 then
begin
Mail_AttachmentInfo.AttachmentInfo_Type:=1;
str:=FMessage.MessageParts.Items.Headers.Values['Content-ID'];
index:=pos('<',str);
FileID:=Copy(str,index+1,length(str)-index-1);
FMail_Info.Mail_Info_Content:=StringReplace(FMail_Info.Mail_Info_Content,'Cid:'+FileID,CheckTxt(TIdAttachment(FMessage.MessageParts.Items).FileName),[rfReplaceAll,rfIgnoreCase]);
end
else
Mail_AttachmentInfo.AttachmentInfo_Type:=2;
FMail_Info.Mail_AttachmentInfoList.Add(Mail_AttachmentInfo);
end;
end;
end;
begin
FMail_Info.Mail_Info_ID:=UIDL;
FMail_Info.Mail_Info_Subject:=CheckTxt(FMessage.Subject);
FMail_Info.Mail_Info_Date:=FMessage.Date;
FMail_Info.Mail_Info_SaveDate:=Now;
FMail_Info.Mail_Info_Form:=CheckTxt(FMessage.From.Text);
FMail_Info.Mail_Info_To:=CheckTxt(FMessage.Recipients.EMailAddresses);
FMail_Info.Mail_Info_Format:='html';
FMail_Info.Mail_Info_Reply:=CheckTxt(FMessage.ReplyTo.EMailAddresses);
FMail_Info.Mail_Info_Priority:=Ord(FMessage.Priority)+1;
FMail_Info.Mail_Info_CC:=CheckTxt(FMessage.CCList.EMailAddresses);
FMail_Info.Mail_Info_BCC:=CheckTxt(FMessage.BccList.EMailAddresses);
FMail_Info.Mail_Info_ReceiptAddress:=FMessage.ReceiptRecipient.Address;
FMail_Info.Mail_Info_ReceiptUser:=FMessage.ReceiptRecipient.User;
if FMail_Info.Mail_Info_ReceiptAddress<>'' then
FMail_Info.Mail_Info_Receipt:=True;
//好像已经自动解码了
{ if FMessage.ContentTransferEncoding='base64' then
FMail_Info.Mail_Info_Content:=DecodeString(FMessage.Body.Text)
else
FMail_Info.Mail_Info_Content:=FMessage.Body.Text;
FMail_Info.Mail_Info_Content:=CheckTxt(FMessage.Body.Text);}
FMail_Info.Mail_Info_Content:=FMessage.Body.Text;
FillAttachmentInfo;
end;