[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

Email with Mapi

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
TAZI
Asked:
TAZI
1 Solution
 
geobulCommented:
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
 
TAZIAuthor Commented:
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
 
xsoftCommented:
listening
0
 
pnh73Commented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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