?
Solved

TIdAttachmentFile filenames ?

Posted on 2008-11-08
5
Medium Priority
?
5,228 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:Grant Fullen
  • 3
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 1000 total points
ID: 22915646
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
 

Author Comment

by:Grant Fullen
ID: 22927511
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
 
LVL 28

Expert Comment

by:2266180
ID: 22941717
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
 

Author Comment

by:Grant Fullen
ID: 22945541
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
 
LVL 28

Expert Comment

by:2266180
ID: 22948427
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question