Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Delphi detect attachment to e-mail and save to a specific director

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA

I need to develop a Delphi Application which can examine incoming e-mail and, depending upon what's in the Subject line, save attachments to specific directories.

Can anyone tell me whether Delphi can do this?

Where can I get some info on this?

Thanks in advance.
 
Yes, this is possible. Have a look at the following code, you should be able to modify it easily for your own purposes.





procedure readmails;
var
NumMails: integer;
outlook: OLEvariant;
namespace: OLEvariant;
folder: OLEvariant;
MailCounter: integer;
MailMessage: variant;
NUMATTACHMENTS: integer;
counter: integer;
ATTFILENAME : variant;
FILENAME : string;
begin

NumMails:=0;

namespace.logon(EmptyParam,EmptyParam,False,True);
folder:=namespace.getdefaultfolder(6);

MailCounter:=1;

PROCESSINGlbl.caption:='Processing 0 of '+inttostr(folder.items.count)+' E-mails';

while (folder.items.count>0) do
begin
NumMails:=NumMails+1;
MailCounter:=folder.items.count;
MailMessage:=folder.items(MailCounter);
PROCESSINGlbl.caption:='Processing '+inttostr(MailCounter)+' of '+inttostr(folder.items.count)+' E-mails';

NUMATTACHMENTS:=MailMessage.attachments.count;
FOR counter:=1 to NUMATTACHMENTS DO
BEGIN
ATTFILENAME:=MailMessage.Attachments.item(counter).filename;
filename:='C:\ATTACHMENTS\'+ATTFILENAME;
MailMessage.attachments.item(counter).saveasfile(filename);
END;

MailMessage.delete;
end;

end;
 
Thanks very much for this code. Could you be so kind as to suggest
what I need to do to overcome

Invalid variant operation.

at

namespace.logon(EmptyParam,EmptyParam,False,True);


I might mention I am using Outlook Express 6 and have a folder
(hanging off the "Inbox Folder") named "Register EM". From whence I
need to extract attachments - to be saved in c:\Register_Em






 
For the above example you will need MS Outlook. It wil not work with Outlook Express (OE) as these two programs only have 2 similarities: You can use them to handle e-mail, they are both published by MS.
Both have their strong and weak points, and in general I could suggest: use Outlook Express for 'home' usage and use MS Outlook for 'business' usage.
When programming towards e-mail, either use the POP3/SMTP or IMAP protocols directly (similar to what OE does) or go the OLE way, like the above example does, but that requires MS Outlook s-)

HTH
TonHu
 
Hi
excuse me jumping on the bandwagon. I have been searching for a way to read Outlook Express emails and use the data sent for a race entry system. Can you tell me how to find out how to use POP3/SMTP etc protocols?
I have done this in MS Outlook using OLE but most home users I know have OE.
Thanks
JimR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top