indy ile mail ve atachment

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
varyemez
Üye
Mesajlar: 262
Kayıt: 01 Oca 2009 11:00
Konum: Bursa
İletişim:

indy ile mail ve atachment

Mesaj gönderen varyemez »

Merhaba ,
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 Error] Unit1.pas(59): E2034 Too many actual parameters
[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.
Lord_Ares
Üye
Mesajlar: 1070
Kayıt: 15 Eki 2006 04:33
Konum: Çorlu

Re: indy ile mail ve atachment

Mesaj gönderen Lord_Ares »

ekte daha once denediğim bir örnek gonderiyorum incelersen faydası olabilir. ben şoyle yapmıştım forma bir adet listbox koydum open dialog ile gondermek istediği seçtirip seçilen dosyanın adını listboxta gösteriyor ve maile ekleyip gonderiyordum oda şöyle

TIdAttachment.Create(IdMessage1.MessageParts,OpenDialog1.FileName);

senin kodunda da orayı değiştirirsen çalışacaktır.
Dosya ekleri
mail.rar
(18.83 KiB) 321 kere indirildi
varyemez
Üye
Mesajlar: 262
Kayıt: 01 Oca 2009 11:00
Konum: Bursa
İletişim:

Re: indy ile mail ve atachment

Mesaj gönderen varyemez »

çok teşekkür ederim ilginze.. çalışmadı , sanırım indy versiyonu ilgili bir durum. projeyi açarken de zaten idSMTP nir bazı property lerini tanımadı. bunların yazılışları değişmiş.. mesela authenticationtype => authtype gibi...

bunları düzelttikten sonra yine tidattachment.create satırında takılıyor.
sizdeki indy nin versiyonu kaç? bendeki 10
Lord_Ares
Üye
Mesajlar: 1070
Kayıt: 15 Eki 2006 04:33
Konum: Çorlu

Re: indy ile mail ve atachment

Mesaj gönderen Lord_Ares »

bende indy9 ve delphi7 kullanıyorum. aşağıda açık kodu vereyim. Formdakileri aşağıya yazdm. ekli dosyada formun görüntüsü var.
1)IdSMTP1
2)IdMessage1
3)OpenDialog1
4) 6 adet edit
5) 1 listbox
6) 1memo
7)1 CheckBox1
8)2 Button

Gönder Buttonum

Kod: Tümünü seç

procedure TForm1.GonderClick(Sender: TObject);
begin
IdSMTP1.Host:=Edit1.Text;
IdSMTP1.Username:=Edit2.Text;
IdSMTP1.Password:=Edit3.Text;
if (Edit1.Text<>'') and (Edit2.Text<>'') and (Edit3.Text<>'') then begin
if CheckBox1.Checked then IdSMTP1.AuthenticationType:=atLogin else
IdSMTP1.AuthenticationType:=atNone;
IdMessage1.From.Address:=Edit4.Text;
IdMessage1.Recipients.EMailAddresses:=Edit5.Text;
IdMessage1.Subject:=Edit6.Text;
IdMessage1.Body.Assign(Memo1.Lines);

try
IdSMTP1.Connect();
except
ShowMessage('Bağlantı Kurulamadı');
end;
try
IdSMTP1.Send(IdMessage1);
ShowMessage('Mail Gönderildi');
finally
IdSMTP1.Disconnect;
end;

end else ShowMessage('Server adresi, kullanıcı adı paraola bilgileri eksik lütfen kontrol ediniz..');



end;

Dosya Ekle buttonum

Kod: Tümünü seç

procedure TForm1.DosyaEkleClick(Sender: TObject);
begin
if OpenDialog1.Execute then begin
                            ListBox1.Items.Add(OpenDialog1.FileName);
                            TIdAttachment.Create(IdMessage1.MessageParts,OpenDialog1.FileName);
                            end;

end;
Dosya ekleri
1.rar
Fomdakiler
(20.85 KiB) 205 kere indirildi
varyemez
Üye
Mesajlar: 262
Kayıt: 01 Oca 2009 11:00
Konum: Bursa
İletişim:

Re: indy ile mail ve atachment (çözüldü)

Mesaj gönderen varyemez »

Hepinize çok teşekkür ederim.. delphi xe ile gelen indy 10.5.7 de biraz farklıymış ...
uses da idattachment değil de idattachmentfile olacakmış (eskisi mülga)

Kod: Tümünü seç

idAttach := TidAttachmentfile.Create(p, 'C:\DELPDENE\Demos\Indy\mailattah\8680001420889_69007.XML' );
 idAttach.ContentType := 'text/XML';
 idAttach.ExtraHeaders.Values['content-id'] := '8680001420889_69007.XML';
yapınca oldu..

bu arada embarcadero nın blog sitesinden bir mail client örneği (smtp ve pop3 ) indirdim orada yazıyor .
buraya da koyarsam belki faydalanan arkadaşlar olur. ayrıca actionlist komponentinin basit bir kullanımına örnek teşkil ediyor.
Dosya ekleri
Indy_10_MailClient.zip
Indy 10 ile mail client örnek proje
(19.08 KiB) 451 kere indirildi
Lord_Ares
Üye
Mesajlar: 1070
Kayıt: 15 Eki 2006 04:33
Konum: Çorlu

Re: indy ile mail ve atachment

Mesaj gönderen Lord_Ares »

hım çok teşekkürler. İncelemek lazım
Cevapla