Solved

Email with Mapi

Posted on 2002-04-11
4
399 Views
Last Modified: 2010-04-04
Hi ..

Below is the code ... I've copied and pasted from a previously asked question.

Everything works fine .. My question is :

1.) When Outlook Express Mail Message is opened, the minimize button is disabled and the application
focus is transfered to the mail message.  By this I mean that the user has to send the email first before
his application can get focus.  Is their a way to attach open Outlook mail message, attach a document,
leave the message box open and give your application focus?

2.)  I wish to be able to add more than 1 documents to this email .. I add the first one fine, I don't
know at the time of adding the first one whether the user would want to add another or send the mail
as is. This is the reason for my wanting to give the application focus again.  How would I go about
doing this and then adding a second image to the open message box.

I thank you sincerely for you assistance in advance

Kind Regards
Mumtaz



uses mapi;

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;
iCount: 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 iCount := 0 to MaxInt do
begin
  if Mail.Values['attachment' + IntToStr(iCount)] = '' then Break;
  AttachCount := AttachCount + 1;
end;

if AttachCount > 0 then
begin
  GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);
  for iCount := 0 TO (AttachCount - 1) do
  begin
    FileName := Mail.Values['attachment' + IntToStr(iCount)];
    Attachments[iCount].ulReserved := 0;
    Attachments[iCount].flFlags := 0;
    Attachments[iCount].nPosition := ULONG($FFFFFFFF);
    Attachments[iCount].lpszPathName := StrNew(PChar(FileName));
    Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
    Attachments[iCount].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 iCount := 0 to (AttachCount - 1) do
begin
  strDispose(Attachments[iCount].lpszPathName);
  strDispose(Attachments[iCount].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;

procedure TForm1.Button1Click(Sender: TObject);

var
mail: TStringList
 
begin
mail := TStringList.Create;
mail.values['to']      := 'Bloke@Geeza.com';
mail.values['subject'] := 'A subject';
mail.values['body']    := 'Some body text (line 1)';
mail.values['attachment0'] := 'c:\winnt\winnt256.bmp';
mail.values['attachment1'] := 'c:\winnt\winnt.bmp';
sendEMail(Application.Handle, mail);
mail.Free;
end;



0
Comment
Question by:TAZI
4 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 100 total points
ID: 6933906
Hi,
The idea is that the message has to be completely prepared before calling MapiSendMail function. No other changes/additions from inside the program are not possible after that. (I think so).

Before calling 'sendEMail', ask the user for other attachments and add them to 'mail' list. Call 'sendEMail' when the user is completely sure that the message is ready for sending.

You may use two buttons for example: 'Attach' and 'Send'. 'Attach' will open a dialog box for selecting a file and add it to 'mail' (you have to count how many files are attached so far). 'Send' on the other hand, will ask 'Is this message ready for sending?' and will call 'sendEMail' function.

Regards, Geo
0
 
LVL 1

Author Comment

by:TAZI
ID: 6933967
Hi ..

MapiSendMail is called only when the Send Button on the mail message is Clicked.

The open email has total focus.  The only thing that it allows me to do is modify the body, type in an email address and then press send.

I want to give my application focus again.  Is this possible.  Also, can the minimize button be enabled in any way

Thanks

Regards
TAZI
0
 
LVL 1

Expert Comment

by:xsoft
ID: 6961533
listening
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9003121
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer from geobul

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now