Board index » delphi » Reading outlook attachment

Reading outlook attachment


2003-12-25 02:59:14 AM
delphi99
D5, Outlook 2003
I am working on a program that transfers some .txt files between offices via
Outlook file attachments.
I would like my program to automatically search through the first few items
of a clients Outlook inbox, see if the file attachments match a file filter,
then prompt to read the text file into my program.
I can get the Outlook component included with D5 to find the attachments,
but I don't know how to actually read them since I can not get the path name
to appear in the MessageDlg below. The "DisplayName" and "FileName"
properties are the same and the "Path" is empty. The "SaveAs" does work
properly, so the information should be available somewhere.
Eventually, I want to read the file into a memo using "LoadFromFile", but
the following snipit will demonstrate what I have done so far:
Thanks for any pointers, Rick
try
Outlook0.Connect;
NmSpace := Outlook0.GetNamespace( 'MAPI' );
Folder := NmSpace.GetDefaultFolder( olFolderInbox );
for i := Folder.Items.Count downto Folder.Items.Count - 2 do begin
MyMail := ( Folder.Items.Item( i ) as MailItem );
Msg := Msg + MyMail.SenderName + #9 + MyMail.Subject + #13#13;
if MyMail.Attachments.Count>0 then
for x := 1 to MyMail.Attachments.Count do begin
Msg := Msg + 'ATTACHMENT: ' +
MyMail.Attachments.Item( x ).PathName + MyMail.Attachments.Item(
x ).FileName + #9 +
MyMail.Attachments.Item( x ).DisplayName + #13+ ;
if x = 1 then
MyMail.Attachments.Item( x ).SaveAsFile( 'c:\' +
MyMail.Attachments.Item( x ).FileName );
end; //if count
end; //for i
MessageDlg( Msg, mtInformation, [ mbOK ], 0 );
finally
NmSpace.Logoff;
Outlook0.Disconnect;
end; //finally
 
 

Re:Reading outlook attachment

"Rick Roen" <Rick at Lake Valley Seed dot com>writes
Quote

I can get the Outlook component included with D5 to find the attachments,
but I don't know how to actually read them since I can not get the path name
to appear in the MessageDlg below. The "DisplayName" and "FileName"
properties are the same and the "Path" is empty. The "SaveAs" does work
properly, so the information should be available somewhere.
You need to set the pathname yourself in the SaveAs method. By the look of
your code you are placing them in the root of your C: drive.
You might consider putting them into the temp folder and deleting them after
you use them.
Quote
MyMail.Attachments.Item( x ).SaveAsFile( 'c:\' +
MyMail.Attachments.Item( x ).FileName );
 

Re:Reading outlook attachment

I'm just wondering where they are now. I see no need to copy them somewhere
else, since I only need to read them.
Rick
"Nelson F." <nbospam>writes
Quote
"Rick Roen" <Rick at Lake Valley Seed dot com>writes
news:XXXX@XXXXX.COM...
>
>I can get the Outlook component included with D5 to find the
attachments,
>but I don't know how to actually read them since I can not get the path
name
>to appear in the MessageDlg below. The "DisplayName" and "FileName"
>properties are the same and the "Path" is empty. The "SaveAs" does work
>properly, so the information should be available somewhere.

You need to set the pathname yourself in the SaveAs method. By the look of
your code you are placing them in the root of your C: drive.
You might consider putting them into the temp folder and deleting them
after
you use them.

>MyMail.Attachments.Item( x ).SaveAsFile( 'c:\' +
>MyMail.Attachments.Item( x ).FileName );



 

Re:Reading outlook attachment

PathName is only valid for the attachments attached by reference. For the
regular (by value) attachments it is always empty.
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Rick Roen" <Rick at Lake Valley Seed dot com>writes
Quote
D5, Outlook 2003

I am working on a program that transfers some .txt files between offices
via
Outlook file attachments.

I would like my program to automatically search through the first few
items
of a clients Outlook inbox, see if the file attachments match a file
filter,
then prompt to read the text file into my program.

I can get the Outlook component included with D5 to find the attachments,
but I don't know how to actually read them since I can not get the path name
to appear in the MessageDlg below. The "DisplayName" and "FileName"
properties are the same and the "Path" is empty. The "SaveAs" does work
properly, so the information should be available somewhere.

Eventually, I want to read the file into a memo using "LoadFromFile", but
the following snipit will demonstrate what I have done so far:

Thanks for any pointers, Rick

try
Outlook0.Connect;
NmSpace := Outlook0.GetNamespace( 'MAPI' );
Folder := NmSpace.GetDefaultFolder( olFolderInbox );

for i := Folder.Items.Count downto Folder.Items.Count - 2 do begin

MyMail := ( Folder.Items.Item( i ) as MailItem );
Msg := Msg + MyMail.SenderName + #9 + MyMail.Subject + #13#13;
if MyMail.Attachments.Count>0 then
for x := 1 to MyMail.Attachments.Count do begin
Msg := Msg + 'ATTACHMENT: ' +
MyMail.Attachments.Item( x ).PathName + MyMail.Attachments.Item(
x ).FileName + #9 +
MyMail.Attachments.Item( x ).DisplayName + #13+ ;
if x = 1 then
MyMail.Attachments.Item( x ).SaveAsFile( 'c:\' +
MyMail.Attachments.Item( x ).FileName );
end; //if count
end; //for i

MessageDlg( Msg, mtInformation, [ mbOK ], 0 );

finally
NmSpace.Logoff;
Outlook0.Disconnect;
end; //finally