receive mapi mail realtime

I have a task where i have to use an application to receive mapi email (from an exchange server) store the email in a database ( i can do that myself) i then have to reply to the person who sent the email with 2 attachments.
I need to know how to do this not using any components apart from those shipped with d5.
Please help ASAP!!
brunnerAsked:
Who is Participating?
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.

intheCommented:
hi,
this project shows how :
http://www.bhnet.com.br/~simonet/archive/mapimail.zip 
 
some code here also from someone posted the other day:

function SendEMail(Handle :THandle;Mail :TStrings) :Cardinal;
type
TAttachAccessArray = array [0..0] of TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;

var
MapiMessage : TMapiMessage;
Receip : TMapiRecipDesc;
Attachments : PAttachAccessArray;
AttachCount : Integer;
i1 : integer;
FileName : String;

begin
fillChar(MapiMessage,SizeOf(MapiMessage),#0);
Attachments:=nil;
fillChar(Receip,SizeOf(Receip),#0);
if Mail.Values['to']<>'' then
begin
Receip.ulReserved:=0;
Receip.ulRecipClass:=MAPI_TO;
Receip.lpszName:=StrNew(PChar(Mail.Values['to']));
Receip.lpszAddress:=StrNew(PChar('SMTP:' + Mail.Values['to']));
Receip.ulEIDSize:=0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @Receip;
end;
AttachCount:=0;
for i1:=0 to MaxInt do
begin
if Mail.Values['attachment'+inttostr(i1)]='' then break;
inc(AttachCount);
end;
if AttachCount>0 then
begin
GetMem(Attachments,SizeOf(TMapiFileDesc)*AttachCount);
for i1:=0 to AttachCount-1 do
begin
FileName:=Mail.Values['attachment'+inttostr(i1)];
Attachments[i1].ulReserved := 0;
Attachments[i1].flFlags := 0;
Attachments[i1].nPosition := ULONG($FFFFFFFF);
Attachments[i1].lpszPathName := StrNew(PChar(FileName));
Attachments[i1].lpszFileName := StrNew(PChar(ExtractFileName(FileName
)));
Attachments[i1].lpFileType := nil;
end;
MapiMessage.nFileCount:=AttachCount;
MapiMessage.lpFiles:=@Attachments^;
end;

if Mail.Values['subject']<>'' then MapiMessage.lpszSubject
:=StrNew(PChar(Mail.Values['subject']));
if Mail.Values['body']<>'' then MapiMessage.lpszNoteText
:=StrNew(PChar(Mail.Values['body']));

Result :=MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle<>0)
or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);

for i1:=0 to AttachCount-1 do
begin
strDispose(Attachments[i1].lpszPathName);
strDispose(Attachments[i1].lpszFileName);
end;

if assigned(MapiMessage.lpszSubject) then
strDispose(MapiMessage.lpszSubject);
if assigned(MapiMessage.lpszNoteText) then
strDispose(MapiMessage.lpszNoteText);
if assigned(Receip.lpszAddress) then strDispose(Receip.lpszAddress);
if assigned(Receip.lpszName) then strDispose(Receip.lpszName);
end;

 

an example of use foir above function would be:

mail:=tstringlist.create;
mail.values['to']:='xyz@zz.com';
mail.values['subject']:='no subject';
mail.values['body']:='no subject';
mail.values['body']:='no subject';
mail.values['attachment0']:='c:\winnt\winnt256.bmp';
mail.values['attachment1']:='c:\winnt\winnt.bmp';
sendEMail(application.handle,mail);
mail.free;


hopefully that should  all help
Regards Barry

 

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
brunnerAuthor Commented:
inthe,

 havn't had a chance to test it though looking at the code this is only how to send the message. In the question i also need to be able to see that there are new messages in the exchange mailbox and get their email addresses from that. I also need this to be realtime as in if a new message is received it will action on this.

I feel if this works you deserve some points regardless so if you can't assist me in full i'll post you another question.
0
JoeBoothCommented:
You need to create a COM object, as shown below:

const

 MAPI_COM_NAME  = 'MAPI.Session';


fObj := CreateOLEObject(MAPI_COM_NAME);

if VarIsEmpty(fInternal)
then
   raise eOLEException.Create('OBJECT
            NOT FOUND',0,'','',0);
{*
The object is a CDOSession object, which has a number of properties and methods that allow you to access the inbox of the exchange server, you can also send mail, read address books, etc.
Unfortunately, there is not a lot of room to document the CDO methods and properties.  If you go to MSDN and look for CDO, you will find that the CDOsession object provides access to all MAPI functions and services...
*}


0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

intheCommented:
hi brunner,
ive only ever used a component for sending mail using mapi so cant really help anymore,this is the component i use:
http://www.torry.ru/vcl/internet/temail2.zip
i know you dont want component but i thought the source code may be a help in achieving what your after.
Regards Barry
0
redhornCommented:
brunner,

There are two kinds of MAPI.
You can send and receive mail easily enough with simple MAPI, but all you can do is poll the mailbox at intervals if you want to check for mail. To receive automatic notification of new mail, you need to use "extended" MAPI, which in my opinion should have been called "insanely overcomplicated" MAPI. This involves creating an object called an Advise Sink which will be attached to the default message store, which ... still awake?

I know you've said you don't want to use  third-party components, but unless you want to re-invent the wheel and the internal-combustion engine, go to the Delphi Super Page and get these files:

mapid10.zip, a translation of the extended MAPI header files.

notify11.zip, a demonstration of how to use the above files to register for new-message notification.

Both these files require Delphi 3 or higher. At the very least, any solution will involve getting the header files. Do yourself a favor and look at the demo in notify11.zip, too.

This might not look like what you want, but I don't think this is a "post a little bit of code" problem -- it is complex. Good luck.
0
brunnerAuthor Commented:
Thanks for all your help guys!!  
It didn't really get me what i wanted but i'll know for next time!! :-)
0
brunnerAuthor Commented:
Thanks for all your help guys!!  
It didn't really get me what i wanted but i'll know for next time!! :-)
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.