gpt4 book ai didi

delphi - 使用 Indy 发送电子邮件不会在 Outlook 中显示附件

转载 作者:行者123 更新时间:2023-12-02 08:03:50 25 4
gpt4 key购买 nike

我遇到以下问题。我创建了一个 Windows 服务,用于发送带有 .xls 附件的电子邮件。如果我使用 Windows Live Mail 或 Web Mail 打开电子邮件,它就可以工作,我可以看到附件。当我尝试使用 Microsoft Outlook 2010 打开电子邮件时,会出现问题,附件不存在,而且我不知道我的代码出了什么问题。

电子邮件标题如下所示

Return-Path: <no-reply@asdf.ro>
Delivered-To: sebi.ciuca@asdf.ro
Received: (qmail 25352 invoked by uid 500); 15 Jul 2015 14:58:23 -0000
Received: by simscan 1.4.0 ppid: 25345, pid: 25349, t: 0.0443s
scanners: attach: 1.4.0 clamav: 0.98.5/m:
Received: from unknown (HELO ab-c11) (task.test@asdf.ro@111.111.111.111)
by mail.absoft.ro with ESMTPA; 15 Jul 2015 14:58:22 -0000
From: "no-reply@asdf.ro" <no-reply@asdf.ro>
Subject: Test Report
To: "Test test" <sebi.ciuca@asdf.ro>
Content-Type: Multipart/Alternative; boundary="wm32hkCMsS=_xUqKLF1OiOMUAOi7ru4ljM"
MIME-Version: 1.0
Date: Wed, 15 Jul 2015 17:58:21 +0300

我用于生成电子邮件的代码是

ExecReport;
var
tMess: TIdMessage;
q: TADOQuery;
Attachment: TIdAttachment;
idtTextPart: TIdText;
fileAttach: string;
subiect: string;
i : Integer;
fName : string;
begin
// FEventLogger.LogMessage( ' Executing ' + IntToStr(FTask.FTaskID) , EVENTLOG_ERROR_TYPE , 0, 2);

//
tMess := TIdMessage.Create;
tMess.Subject := FTask.FDenumire;

tMess.ContentType := 'text/html';

try
q := TADOQuery.Create(nil);
q.Connection := fConn;
q.CommandTimeout := FTask.FTimeout;
q.SQL.Text := FTask.FQueryString;
q.Open;
q.First;
except
on E: Exception do
begin
FEventLogger.LogMessage(' Error! ' + E.Message,
EVENTLOG_ERROR_TYPE, 0, 2);
q.Free;
LogErrorExecution(E.Message);
Exit;
end;
end;

Subiect := FTask.FDenumire;

// dtSource := TDataSource.Create(nil);
// dtSource.dataset := q;
fileAttach := CreateExcelDocument(q,False);

tMess := TIdMessage.Create;
tMess.Clear;
tMess.ContentType := 'Multipart/Alternative';
tMess.Subject := subiect;

idtTextPart := TIdText.Create(tMess.MessageParts, nil);
idtTextPart.ContentType := 'text/plain';
idtTextPart.Body.Add(' ');

idtTextPart := TIdText.Create(tMess.MessageParts, nil);
idtTextPart.ContentType := 'text/html';

Attachment := TIdAttachmentFile.Create(tMess.MessageParts, fileAttach);

if q.RecordCount > 0 then
begin

idtTextPart.Body.Text := '<html><body bgcolor="#DCEEFC">';
if (FTask.FHeaderID <> '') then
begin
idtTextPart.Body.Text := idtTextPart.Body.Text + BuildTable(q);
end;
idtTextPart.Body.Text := idtTextPart.Body.Text + ' </body></html>';

self.SendMail(s, tMess);

end;

q.Close;
q.Free;

end;

最佳答案

如果有附件,内容类型如何为“多部分/替代”? Outlook 不知道您的 xls 文件是什么,因此它会选取它所知道的正文部分 - 纯文本或 HTML,并丢弃它不理解的正文风格 (xls)。

您是否尝试过“多部分/混合”内容类型?这样,您将向 Outlook 发出信号,表明您的 xls 文件是附件,与邮件正文无关。

更新

如果您想要纯文本/html 部分和附件,则消息结构应该是

multipart/mixed
multipart/related
text/plain
text/html
attachment

查看 Outlook 为各种邮件创建的 MIME 结构 - 您可以在 OutlookSpy 中看到它(我是它的作者)- 选择与您想要的类似的邮件,单击 OutlookSpy 工具栏上的 IConverterSession 按钮,然后单击 MAPIToMIMEStm。

关于delphi - 使用 Indy 发送电子邮件不会在 Outlook 中显示附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31446612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com