Solved

Email with Mapi

Posted on 2002-04-11
4
421 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 65
Installshield for Embarcadero EX 10.1 Berlin 4 60
Slow Restore if incremental backups using RDiff.exe 4 30
shape, triangle, dbctrlgrid 3 17
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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