如何在Delphi应用程序中阅读HTML格式的电子邮件? [英] How can I read email with HTML format in a Delphi application?

查看:133
本文介绍了如何在Delphi应用程序中阅读HTML格式的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个程序,可以从Exchange 2007中读取电子邮件.但是,它只能读取纯文本格式的电子邮件正文.当我尝试以HTML格式检索电子邮件时,我的软件无法读取正文,并且始终为空白.我正在使用Delphi 2007和IMAP 9.

I have created a program that can read email from Exchange 2007. However, it can only read the body of the email in plain-text format. When I tried to retrieve email in HTML format, my software cannot read the body and it always blank. I am using Delphi 2007 and IMAP 9.

这是我的代码:

procedure TForm1.tmrCekTimer(Sender: TObject);
var
  TheFlags: TIdMessageFlagsSet;
  TheUID: string;
  TheMsg: TIdMessage;
  MailBoxName: string;
  MyClass: TComponent;
begin
  MailBoxName := 'INBOX';
  if TheImap.SelectMailBox(MailBoxName) = False then
  begin
    Screen.Cursor := crDefault;
    ShowMessage('Error selecting '+MailBoxName);
    Exit;
  end;
  TheMsg := TIdMessage.Create(nil);
  nCount := TheImap.MailBox.TotalMsgs;
  TheMsg.ContentType := 'multipart/alternative';
  TheMsg.Encoding := meMime;
  if nCount = 0 then begin
    StringGrid1.RowCount := 2;
    StringGrid1.Cells[0, 1] := '';
    StringGrid1.Cells[1, 1] := '';
    StringGrid1.Cells[2, 1] := '';
    StringGrid1.Cells[3, 1] := '';
    ShowMessage('There are no messages in '+MailBoxName);
  end else begin
    StringGrid1.RowCount := nCount + 1;
    for i := 0 to nCount-1 do begin
      TheImap.GetUID(i+1, TheUID);
      TheImap.UIDRetrieveFlags(TheUID, TheFlags);
      TheImap.UIDRetrieve(TheUID, TheMsg);
      //TheImap.UIDRetrieveHeader(TheUID, TheMsg);
      StringGrid1.Cells[0, i+1] := IntToStr(i+1);
      StringGrid1.Cells[1, i+1] := TheMsg.From.Address;
      //StringGrid1.Cells[1, i+1] := TheUID;
      if mfSeen in TheFlags then
        StringGrid1.Cells[2, i+1] := 'Yes'
      else begin
        StringGrid1.Cells[2, i+1] := 'No';
      end;
    end;
 end;

推荐答案

MIME编码的电子邮件的内容(例如HTML电子邮件(如果还存在纯文本和/或附件))存储在TIdMessage.MessageParts属性中,不在TIdMessage.Body属性中.您需要查看电子邮件的实际ContentType属性,以了解TIdMessage将电子邮件解析为哪个属性.

The contents of MIME-encoded emails, such as HTML emails (if plain-text and/or attachments are also present) are stored in the TIdMessage.MessageParts property, not in the TIdMessage.Body property. You need to look at the email's actual ContentType property to know which property TIdMessage parsed the email into.

这篇关于如何在Delphi应用程序中阅读HTML格式的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆