Solved

Email with Mapi

Posted on 2002-04-11
4
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

726 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