I am writing an Android program using Delphi (Rad Studio 10.1) that will send data in a text file via email (using SMTP, etc.).
I am currently able to send email, but not with an attachment. The program appears to freeze when making the attachment file using the following code:
Attachment:=TIdAttachmentFile.Create(IdMessage1.MessageParts, (GetHomePath+'/test.txt'));
The path is not wrong because I am able to read the file to a memo using the following:
Memo2.Lines.LoadFromFile(GetHomePath+'/Test.txt');
Here is the entirety of my code related to the attachment:
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);
After this, I simply connect to a TIdSMTP and send the message. Again, there is no problem sending the email without the lines related to TIdAttachmentFile.
If I do include the line
AttMemory := TIdAttachmentMemory.Create(IdMessage1.MessageParts);
I get an email with an attachment, however, the attachment had no name, is empty, and cannot be related to the file I want to attach because to send the email, lines related to the attachment file must be commented out.