【发布时间】:2016-10-29 22:23:12
【问题描述】:
我正在使用 Delphi (Rad Studio 10.1) 编写一个 Android 程序,它将通过电子邮件(使用 SMTP 等)在文本文件中发送数据。
我目前可以发送电子邮件,但不能发送附件。使用以下代码制作附件文件时,程序似乎卡住了:
Attachment:=TIdAttachmentFile.Create(IdMessage1.MessageParts, (GetHomePath+'/test.txt'));
路径没有错,因为我可以使用以下命令将文件读入备忘录:
Memo2.Lines.LoadFromFile(GetHomePath+'/Test.txt');
这是我与附件相关的全部代码:
Text := TIdText.Create(IdMessage1.MessageParts);
Text.ContentType := 'text/plain';
Text.Body.Add('Hello!');
Attachment := TIdAttachmentFile.Create(IdMessage1.MessageParts, (GetHomePath+'/test.txt'));
with Attachment do
begin
ContentType := 'text/plain';
FileName := 'test.txt';
end;
IdMessage1.ContentType := 'multipart/mixed';
AttMemory := TIdAttachmentMemory.Create(IdMessage1.MessageParts);
之后,我只需连接到 TIdSMTP 并发送消息。同样,发送没有与 TIdAttachmentFile 相关的行的电子邮件也没有问题。
如果我确实包含该行
AttMemory := TIdAttachmentMemory.Create(IdMessage1.MessageParts);
我收到一封带有附件的电子邮件,但是,附件没有名称,是空的,并且不能与我要附加的文件相关,因为要发送电子邮件,必须注释掉与附件文件相关的行。
【问题讨论】:
标签: android delphi smtp email-attachments indy