我在制作邮件接收器时,用的是NMPOP3控件,(控件与邮件服务器连接是没有问题的)但就是在显示邮件的主体内容信息时不能显示出来(
procedure TForm1.Button2Click(Sender: TObject);
begin
nmpop31.GetMailMessage(10);//假设是第10封信
edit6.Text :=nmpop31.MailMessage.From;
edit7.Text :=nmpop31.MailMessage.Subject;//这儿我在测试中给自己发了一封信是中文的,为这何变成了一堆字母呢;
edit8.Text :=nmpop31.MailMessage.MessageId;
edit11.Text :=nmpop31.MailMessage.ClassName;
memo4.Lines.Assign(nmpop31.MailMessage.Head);
memo5.Lines.Assign(nmpop31.MailMessage.Body);//就这一步为何不能在memo5控件中显示邮件的主要内容呢?
end;
)
procedure TForm1.Button2Click(Sender: TObject);
begin
nmpop31.GetMailMessage(10);//假设是第10封信
edit6.Text :=nmpop31.MailMessage.From;
edit7.Text :=nmpop31.MailMessage.Subject;//这儿我在测试中给自己发了一封信是中文的,为这何变成了一堆字母呢;
edit8.Text :=nmpop31.MailMessage.MessageId;
edit11.Text :=nmpop31.MailMessage.ClassName;
memo4.Lines.Assign(nmpop31.MailMessage.Head);
memo5.Lines.Assign(nmpop31.MailMessage.Body);//就这一步为何不能在memo5控件中显示邮件的主要内容呢?
end;
)
Caption := Base64Decode(IdMessage.From.Text);
Caption := Base64Decode(IdMessage.Subject.Text);
以下是自己写的,利用Indy9內建De/EncoderMIME解码..//------------------------------------------------------------------------------
//Base64Decode
//------------------------------------------------------------------------------
function TMainForm.Base64Decode(strInput : string) : string;
var
strDecode : string;
posStart: Integer;
posEnd : Integer;
begin
while pos('=?gb2312?b?',lowercase(strInput)) > 0 do
begin
try
posStart := pos('=?gb2312?b?',lowercase(strInput));
posEnd := pos('?=',lowercase(strInput));
strDecode := strDecode + copy(strInput,1,posStart-1) + IdDeMIME.DecodeString(copy(strInput,posStart+11,posEnd-posStart-11));
strInput := copy(strInput,posEnd+2,length(strInput)-posEnd-1);
finally
Application.ProcessMessages;
end;
end;
strDecode := strDecode + strInput;
result := strDecode;
end;//------------------------------------------------------------------------------
//Base64Encode
//------------------------------------------------------------------------------
function TMainForm.Base64Encode(strInput : string) : string;
var
strEncode : string;
begin
strEncode := IdEnMIME.EncodeString(strInput);
result := strEncode;
end;//------------------------------------------------------------------------------
PS.
IdDeMIME是IdDecoderMIME
IdEnMIME是IdEncoderMIME