Ciu*_*caS 2 delphi email outlook indy
我有以下问题.我创建了一个发送带.xls
附件的电子邮件的Windows服务.如果我用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
Run Code Online (Sandbox Code Playgroud)
我用来生成电子邮件的代码是
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;
Run Code Online (Sandbox Code Playgroud)
如果您有附件,内容类型如何是"Multipart/Alternative"?Outlook不知道你的xls文件是什么,因此它会获取它所知道的正文部分 - 纯文本或HTML并丢弃它不理解的正文风格(xls).
你尝试过"multipart/mixed"内容类型吗?这样,您将向Outlook发出信号,表明您的xls文件是附件,与邮件正文无关.
UPDATE
如果你想要纯文本/ html部分和附件,你的消息结构应该是
multipart/mixed
multipart/related
text/plain
text/html
attachment
Run Code Online (Sandbox Code Playgroud)
查看Outlook为各种邮件创建的MIME结构 - 您可以在OutlookSpy中看到它- 选择类似于您想要的邮件,单击OutlookSpy工具栏上的IConverterSession按钮,然后单击MAPIToMIMEStm.
归档时间: |
|
查看次数: |
840 次 |
最近记录: |