Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where is the result in this function? 1

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA
I need the procedure which follows this function to use
the result generated by the function.

Having got the function, designed by Sven Sonderegger and
other gurus, from the Web somewhere. Thanks guys! :)

But can someone tell this mere mortal where the result of the function is to be found?
What do I need at Line A in the procedure?

I might mention that this (hopefully) all results in e-mail
being sent from a Delphi Project.


function SendMailMAPI(const Subject, Body, FileName, SenderName, SenderEMail,
RecepientName, RecepientEMail: String) : Integer;
var
message: TMapiMessage;
lpSender,
lpRecepient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(message, SizeOf(message), 0);
with message do
begin
if (Subject<>'') then
begin
lpszSubject := PChar(Subject)
end;
if (Body<>'') then
begin
lpszNoteText := PChar(Body)
end;
if (SenderEMail<>'') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (SenderName='') then
begin
lpSender.lpszName := PChar(SenderEMail)
end
else
begin
lpSender.lpszName := PChar(SenderName)
end;
lpSender.lpszAddress := PChar('SMTP:'+SenderEMail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;
if (RecepientEMail<>'') then
begin
lpRecepient.ulRecipClass := MAPI_TO;
if (RecepientName='') then
begin
lpRecepient.lpszName := PChar(RecepientEMail)
end
else
begin
lpRecepient.lpszName := PChar(RecepientName)
end;
lpRecepient.lpszAddress := PChar('SMTP:'+RecepientEMail);
lpRecepient.ulReserved := 0;
lpRecepient.ulEIDSize := 0;
lpRecepient.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @lpRecepient;
end
else
begin
lpRecips := nil
end;
if (FileName='') then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
FillChar(FileAttach, SizeOf(FileAttach), 0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(FileName);
nFileCount := 1;
lpFiles := @FileAttach;
end;
end;
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule=0 then
begin
Result := -1
end
else
begin
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM<>nil then
begin
Result := SM(0, Application.Handle, message, MAPI_DIALOG or
MAPI_LOGON_UI, 0);
end
else
begin
Result := 1
end;

finally
FreeLibrary(MAPIModule);
end;
end
if Result<>0 then
begin
MessageDlg('Error sending mail ('+IntToStr(Result)+').', mtError, [mbOk],
0)
end;
end;



procedure TfrmRegister.btbnEmailRegisterClick(Sender: TObject);
var
StrMsg : String;
begin

strMsg := WHAT?? ..... A

// To send e-mail message
ShellExecute (Handle, 'open', pChar (strMsg),
'', '', SW_SHOW);

end;
 

why are you using the shellexecute ?
just a simple procedure as shown below will send the mail

procedure TForm1.Button1Click(Sender: TObject);
begin
SendMailMAPI('Hello test','This is a test mail', 'c:\n.txt', 'Earl', 'Test@yahoo.com','Delphiman', 'delphiman@yahoo.com') ;

end;
 
I have marked where the result is set:
Code:
 if MAPIModule=0 then
  begin
    Result := -1 {*** Result set here ***}
  end
  else
  begin
    try
      @SM := GetProcAddress(MAPIModule, 'MAPISendMail');
      if @SM<>nil then
      begin
        Result := SM(0, Application.Handle, message, MAPI_DIALOG or
                     MAPI_LOGON_UI, 0); {*** Result set here ***}
      end
      else
      begin
        Result := 1 {*** Result set here ***}
      end;

I agree with earlrainer - I think you're getting a bit muddled. You use the ShellExecute line in conjunction with the mailto protocol.

The MAPI method should work as earlrainer has indicated.

Hope this helps!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
earlrainer

Thanks Mate! But you are deviating from my problem in that your code does not show how to attach a file to it. Such as c:\h\MyFile.gdb[/i].

I can generate &quot;strMsg &quot; which contains the &quot;To:&quot;, &quot;Subject&quot; and &quot;Body&quot; parts of the required e-mail. But it doesn't contain an &quot;attachment&quot; such as the above file. Nor am I using MAPI which I must.

It appears that the code which I refer to handles that ... but I don't know where to find the required total &quot;Result&quot;.

Stretchwickster
>I think you're getting a bit muddled

Tell me about it!! :)

My problem with the &quot;Result&quot; which you refer to is that it merely returns in &quot;-1&quot; or &quot;1&quot; . Which is about as useful to me as a wheelbarrow in a rowing-boat! :) :)

I can't see how I take advantage of this brilliant code by
sticking the result into (say)strMsg. Which I can do something with. As in ...

ShellExecute (Handle, 'open', pChar (strMsg),
'', '', SW_SHOW);


The suggested code by earlrainer does not show me how to pick up the derived Result of the mentioned code. Whilst I have already detected that my intention to use &quot;ShellExecute&quot; is raising an exception.
 
Notice in Earlrainer's code:
Code:
 SendMailMAPI('Hello test','This is a test mail', 'c:\n.txt', 'Earl', 'Test@yahoo.com','Delphiman', 'delphiman@yahoo.com') ;
The third parameter (Filename of type string) is: 'c:\n.txt'
Then follow the code to this point:
Code:
 if (FileName='') then
    begin
      nFileCount := 0;
      lpFiles := nil;
    end
    else
    begin
      FillChar(FileAttach, SizeOf(FileAttach), 0);
      FileAttach.nPosition := Cardinal($FFFFFFFF);
      FileAttach.lpszPathName := PChar(FileName);
      nFileCount := 1;
      lpFiles := @FileAttach;
    end;
This portion basically checks if filename is blank, if so it sets a file count to zero and the files to nil. If, however, there is a value for the filename string then the else part is executed i.e. FileAttach is used to setup the attachment - the file count is set to 1 and the attachment is assigned to lpFiles. Try earlrainer's example of a call to the SendMailMAPI function, ensuring that the file specified actually exists in the location given, step thru the code (set breakpoints where necessary) and see what happens. If you can wait til Tuesday (when I return to work) I can send you a working version of my implemented MAPI code.

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
A question for Stretchwickster:

I try to use what I have found in the VCL (and assume came from the classic Pascal Age):
Code:
function GetAValue : Integer;
begin
   Result := -1;  //   always set the false value on the first line
   if ThingsAreOkay then
       Result := ANonFailureValue

   else if ThingsAreOkayInADifferentWay then
       Result := ADifferentNonFailureValue;
end;

Comments?

Cheers
 
I think that it is clear from the code that Result indicates whether or not creation of the e-mail (along with an attachment) was successfully created. That the code works!

How I can expect to benefit from this code however - other than to find that Result indicates that in fact it merely works- remains lost on me.

Meanwhile I greatly appreciate and value the advice of Stretchwicksterand earlrainer as a result of which I am now &quot;getting somewhere&quot; I think. Whilst it appears that all the code in question provides other protection and benefits from being dependant upon MAPI - which I would like to understand.

I know (and can use) simpler methods of sending e-mail (without a attachment) but then I would not be involved with MAPI. Which I believe is the way to go.



 
So delphiman, are you able to send mail using the MAPI code? Or not? Let me know if you want me to send a working example to you.

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
I am still floundring around! :)

>Let me know if you want me to send a working example to >you.

That's very kind of you!! :) :)

Use delphiman@bigpond.com.
 
That is EXACTLY what I needed.

Thanks from Melbourne &quot;downunder&quot; mate!!

Just for that ... we'll let you win at cricket (anything) next time! :) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top