首页 > 解决方案 > 使用 Indy 和 ContentType = 'multipart/mixed' 发送电子邮件的问题

问题描述

我使用下面的代码从使用 Indy 的 Delphi 应用程序发送电子邮件。

我刚刚离开了我日常工作的核心部分:

MailMessage.From.Name:= UserName;
MailMessage.Encoding := meDefault;
MailMessage.Subject := MessageObject;
with TIdText.Create(MailMessage.MessageParts, nil) do begin
  ContentType := 'multipart/alternative';
end;
with TIdText.Create(MailMessage.MessageParts, nil) do
begin
  Body.Text:= MessageText; // MessageText could be eithr HTML or TEXT
  ContentType := 'text/html';
end;
// recipients lists are populated
PrepareToList;
PrepareccList;
PrepareBccList;
// attachments are added to the MailMessage
AddAttachments;
MailMessage.ContentType :=  'multipart/mixed';
//usage of TIdSMTP to send mail
SMTP.Connect;
SMTP.Send(MailMessage);

上面的代码不知何故适用于大多数 SMTP 服务器,在 Outlook 中收到的消息如下所示:

在 Outlook 中看到的邮件:正常情况

...但是当我使用特定的“有问题”的 SMTP 服务器时,我看到:

在 Outlook 中看到的邮件:奇怪的情况

第一种情况正常,第二种情况很奇怪。

奇怪的是,当使用特定的 SMTP 服务器时,我重现了这个问题,其他的都很好。

您能否给我一些提示以进一步了解发生了什么?

标签: delphismtpindy

解决方案


推荐阅读