我想发送RTF格式的邮件(包括图片,附带文件与否)。 我尝试了以下代码(与许多其他ContentType)但我总是收到纯文本。 有人知道如何用Delphi XE3做到这一点吗?
procedure TForm1.Button1Click(Sender: TObject);
var
zMessage: TIdMessage;
zSMTP: TIdSmtp;
begin
zSMTP := TIdSMTP.Create(Application);
zMessage := TIdMessage.Create;
zMessage.Recipients.EMailAddresses := 'dce@v.com';
zMessage.Subject := 'Test RTF';
zMessage.ContentType := 'multipart/mixed';
// zMessage.ContentType := 'multipart/alternative';
zMessage.From.Address := 'dce@v.com';
zMessage.From.Name := 'DCE';
// zMessage.Body.LoadFromFile('c:\TEMP\test.rtf');
with TIdText.Create(zMessage.MessageParts) do
begin
ContentType := 'text/richtext';
Body.LoadFromFile('c:\TEMP\test.rtf');
end;
zSMTP.Host := 'm.v.com';
zSMTP.UserName := 'dce@v.com';
zSMTP.Password := 'dce';
zSMTP.Connect;
zSMTP.Send(zMessage);
end;
我也试过这段代码:
procedure TForm1.Button2Click(Sender: TObject);
var
zMBuilder: TIdMessageBuilderRtf;
zMyMemoryStream: TMemoryStream;
zMessage: TIdMessage;
zSMTP: TIdSmtp;
begin
try
zSMTP := TIdSMTP.Create(Application);
zMessage := TIdMessage.Create;
zMessage.Recipients.EMailAddresses := 'dce@v.com';
zMessage.Subject := 'Test RTF 2';
zMessage.ContentType := 'multipart/mixed';
zMessage.From.Address := 'dce@v.com';
zMessage.From.Name := 'DCE';
zMBuilder := TIdMessageBuilderRtf.Create;
zMyMemoryStream := TMemoryStream.Create;
zMBuilder.RtfType := idMsgBldrRtfRichtext;
zMyMemoryStream.LoadFromFile('c:\TEMP\test.rtf');
zMBuilder.Rtf.LoadFromStream(zMyMemoryStream);
zMBuilder.FillMessage(zMessage);
zSMTP.Host := 'm.v.com';
zSMTP.UserName := 'dce@v.com';
zSMTP.Password := 'ddd';
zSMTP.Connect;
zSMTP.Send(zMessage);
zSMTP.DisConnect;
finally
zMyMemoryStream.Free;
zMBuilder.Free;
end;
end;
提前致谢。