• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

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!!
0
brunner
Asked:
brunner
1 Solution
 
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
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now