TIdAttachmentFile filenames ?

I am working with attaching files in an email with INDY 'TIdAttachmentFile '. It all works and attaches the file but the file name of  the file allways gets changed to application001 .
I just want the attachments filename to show up as they are.
procedure below.
I call the procedure as

if opendialog1.Execute then

 TIdAttachmentFile.Create(idmessage1.MessageParts, opendialog1.FileName);

 AddAttachments;
procedure TForm1.AddAttachments;
var li: TListItem;
 
 idx: Integer;
 
begin
 
//clear the attachment listview
 
 lvAttachments.Items.Clear;
 
//loop through Idmessage and count parts
 
 for idx := 0 to Pred(Idmessage1.MessageParts.Count) do
 
 begin
 
 li := lvAttachments.Items.Add;
 
// Check if Idmessage contains any attachments&
 
 if Idmessage1.MessageParts.Items[idx] is TIdAttachmentFile then
 
 begin
 
//if so, get the file names&
 
 li.Caption := TIdAttachmentFile(Idmessage1.MessageParts.Items[idx]).Filename;
 
//and add them to the listview
li.SubItems.Add(TIdAttachmentFile(Idmessage1.MessageParts.Items[idx]).ContentType);
 
 end
 
 else
 
 begin
 
 
 
 li.Caption := Idmessage1.MessageParts.Items[idx].ContentType;
  application.ProcessMessages;
 end;
 
 end;
 
end;

Open in new window

Grant FullenNONEAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

2266180Commented:
here is my test code.

as you can see, it works. I am using indy 10.2.3
Test it. does it work for you? If not, then consider upgrading to a newer version of indy :)
uses IdMessage, IdAttachmentFile, IdBaseComponent;
 
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
var m:TIdMessage;
begin
  m:=TIdMessage.Create(nil);
  try
    TIdAttachmentFile.Create(m.MessageParts, 'c:\test.jpg');
    showmessage(TIdAttachmentFile(m.MessageParts.Items[0]).Filename);
  finally
    freeandnil(m);
  end;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Grant FullenNONEAuthor Commented:
I tried your code and seems the same result. It sends the file but no name .
I am tesing Delphi 2009 Trial so the version of indy they have packaged is what i am using here.

var m:TIdMessage;
begin
  m:=TIdMessage.Create(nil);
  try
    TIdAttachmentFile.Create(m.MessageParts, 'D:\MySource\AvJobs\New Folder.zip');
    showmessage(TIdAttachmentFile(m.MessageParts.Items[0]).Filename);
  finally
    freeandnil(m);
  end;

Open in new window

0
2266180Commented:
I don't have delphi 2009, but I tested the code and the name IS being send. so, how do you test to see if the filename is sent or not? It might be that your email client is not reading the filename correctly.
do you look at the headers sent? that's the best way.
0
Grant FullenNONEAuthor Commented:
Thanks for the reply. I have tested it with yahoo, gmail .l
Yahoo shows each file as application1, application2 etc,
Gmal show no file name.
Ciuly have you sent a file with your test code and check that the file was on the email server and the filename was correct ?
Thanks
 
0
2266180Commented:
following is my test code and result in gmail. as you can see, it works.

I don't know what version tehre is in D2009, buyt lets jsut assume it's buggy (though I really doubt it).
so, download latest version from http://www.indyproject.org/Sockets/Docs/Indy10Installation.EN.aspx and follow the instructions on that page.
you only need to do steps 1 and 2. ignore step 3 and in of step 4, instead of adding the paths to the library path you will add it to project-search path.
this way you will compile your project with that specifix indy version. this is how I am doing it: I am using delphi 7 which comes with indy 9. I change the project paths to include paths to indy 10 and create everything at runtime (as you can see, there are no components on my form). this tehnique allows me to use many different indy versions with the same delphi version.
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
uses IdMessage, IdAttachmentFile, IdBaseComponent, IdSmtp, IdTCPClient,
  IdSMTPBase;
 
procedure TForm1.FormCreate(Sender: TObject);
var m:TIdMessage;
begin
  m:=TIdMessage.Create(nil);
  try
    TIdAttachmentFile.Create(m.MessageParts, 'c:\test.bmp');
    showmessage(TIdAttachmentFile(m.MessageParts.Items[0]).Filename);
    m.From.Address:=xxxx@ciuly.com;// put yours here
    m.Recipients.Add.Address:=xxxx@gmail.com;// put yours here
    with tidsmtp.create(nil) do
    try
      Connect(my mail server ip address, 25);
      Send(m);
    finally
      free;
    end;
  finally
    freeandnil(m);
  end;
end;
 
end.

Open in new window

test-email.JPG
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.