rad - Delphi Indy Attachments not working -


i have app needs ftp uploads network drive. using indy this. then, when file located on network drive , uploaded ftp server, want email same file colleague.

i using code below this. email gets sent fine, reason, attachments never make it. doing wrong in code?

i add file (during ftp process) public (form) member variable called emailfiles (tstringlist), pass procedure. here take list of file names , try add tidmessage component. when email sent, no attachments....

    procedure tfrmmain.sendemail(frommail, tomail, subject, body: string;   attachments: tstringlist); var   i: integer;   att : tidattachmentfile; begin    memo1.lines.add('');    memo1.lines.add('starting email service...');    smtp.host := 'mail.*****.com';    smtp.username := '***un***';    smtp.password := '***pw***';    try      msg1.from.address := frommail;      msg1.recipients.emailaddresses := tomail;      msg1.subject := subject;      msg1.body.add(body);       //add attachment(s)      if attachments.count <= 0 memo1.lines.add('warning: cannot detect attachments email...');       := 0 attachments.count - 1        begin           if fileexists(attachments[i])             begin               //memo1.lines.add('adding attachment ' + msg1.messageparts.items[0].filename + '...');               att := tidattachment.create(msg1.messageparts, attachments[i]);               msg1.messageparts.add;  //an attempt explicitly add att object, no avail               memo1.lines.append('added attachment ' + attachments[i]);               att.free;             end           else             begin               memo1.lines.add('could not locate file: ' + attachments[i] + ' email attachment!');             end;        end;         //try send message        try          smtp.connect;          if msg1.messageparts.attachmentcount > 0 begin            smtp.send(msg1);            memo1.lines.add('sent email successfully!');          end           else begin             if messagedlg('do want send email without attachments?', mtconfirmation, [mbyes, mbno], 0) = mryes               begin                 smtp.send(msg1);                 memo1.lines.add('sent email successfully, without attachments!');               end             else               memo1.lines.add('no files attached email message - cannot send!');           end;         except          on e:exception            begin              messagedlg('could not send email message!' + #13#10 + e.message, mterror, [mbok], 0);            end;        end;     except      on e:exception        showmessage('could not connect smtp server' + #13#10 + e.message);    end; end; 

don't free att object, , calling msg1.messageparts.add won't anything.

if fileexists(attachments[i]) begin         tidattachment.create(msg1.messageparts, attachments[i]); end else begin   memo1.lines.add('could not locate file: ' + attachments[i] + ' email attachment!'); end; 

you need specify email content type:

msg1.contenttype := 'multipart/mixed'; 

please refer indy blog, see section "html , non-related attachments , no plain-text"


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -