Have tried the code, made some changes too. I get the all messages successfully.
Problem is that the attachment filenames are blank. Even If I save it with, say 'abc.csv', then 0 bytes file is created.
procedure TForm1.btn_SaveattachmentsClick(Sender: TObject);var TheUID,fName: string; TheMsg: TIdMessage; nMsgPartsCount: integer;begin TheUID := StringGrid1.Cells[1, StringGrid1.Selection.Top]; try TheMsg := TIdMessage.Create(nil); TheImap.UIDRetrieveStructure(TheUID,TheMsg); for nMsgPartsCount := 0 to TheMsg.MessageParts.Count-1 do begin if TheMsg.MessageParts[nMsgPartsCount] is TIdAttachment then begin if TheMsg.MessageParts[nMsgPartsCount] is TIdAttachmentFile then begin fName := TIdAttachmentFile(TheMsg.MessageParts.Items[nMsgPartsCount]).Filename; if (fName <> '') then begin fName := ExtractFilePath(Application.exename)+'download\' + fName; TIdAttachmentFile(TheMsg.MessageParts.Items[nMsgPartsCount]).SaveToFile(fName); ShowMessage('Attachment saved '+fName); end; end else ShowMessage('Attachment ignored - Not recognised as a file'); end; end; finally TheMsg.Destroy; end;end;
Problem is that the attachment filenames are blank. Even If I save it with, say 'abc.csv', then 0 bytes file is created.
Open in new window