Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Email with Mapi

Posted on 2002-04-11
4
Medium Priority
?
455 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 400 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

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!

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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