delphi XE ve indy 10 kullanarak mail gönderebilyorum ancak iş attachment kısmına gelince bir türlü başaramadım.. Kodlar aşağıda .
Kod: Tümünü seç
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase,
IdSMTP, StdCtrls,idattachment,idtext,idmessageparts;
.............
..............
............
----------------------------
var
idAttach: TidAttachment;
idText1: TidText;
idText2: TidText;
p: TidMessageParts;
slBody: TStringList;
begin
idMessage1.Recipients.Add;
idMessage1.Recipients[0].Address := 'moruc@hotmail.com';
idmessage1.From.Text:='mtoruc@gmail.com';
p := idMessage1.MessageParts;
slBody := TstringList.Create;
try
slBody.Add('<html>');
slBody.Add('<head>');
slBody.Add('</head>');
slBody.Add('<body>');
slBody.Add('<br /><br /><b><font color="red">Here is the image:</font></b><br /><br /><br />');
slBody.Add('<img src="cid:mavilogo.jpg" />');
slBody.Add('</body>');
slBody.Add('</html>');
idText1 := TidText.Create(p, slBody);
idText1.ContentType := 'text/html';
idText2 := TidText.Create(p);
idText2.ContentType := 'text/plain';
idText2.Body.Text := slBody.Text;
// This shows how to add an attachment
idAttach := TidAttachment.Create(p, 'mavilogo.jpg' ); // burada hata veriyor
idAttach.ContentType := 'image/jpeg';
idAttach.ContentDisposition := 'inline';
idAttach.ExtraHeaders.Values['content-id'] := 'mavilogo.jpg';
idMessage1.Body.Assign(idtext2.Body);
idAttach.DisplayName := 'mavilogo.jpg';
idMessage1.ContentType := 'multipart/mixed';
idsmtp1.Host:='mail.xxxx.com.tr';
idsmtp1.Username:='mehmet@xxxxx.com.tr';
idsmtp1.Password:='xxxx';
idSMTP1.Connect;
idSMTP1.Send(idMessage1);
finally
idSMTP1.Disconnect;
slBody.Free;
Showmessage('done');
end;
end;
[DCC Warning] Unit1.pas(59): W1020 Constructing instance of 'TIdAttachment' containing abstract method 'TIdAttachment.OpenLoadStream'
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
nerede hata yapıyorum aklım ermedi.. idattach olmadan normal mesajı gönderebiliyor.