Using Delphi7, I am attempting to send emails from my application. I know that there are many ways to do this easily, and in some parts of my app I am creating an email and having the new email form come up (so that the user can amend the email and then click "Send").
However, I need to perform some email tasks in the background and I do not want to use as smtp server due to it needing to be configured (host, username,etc...). I can get the email created and sent fine, without the new email form coming up BUT the Outlook Send/Receive form comes to the foreground and basically locks out my app until the emails are sent!
I have looked at locating the window handle and trying to minimise it, but this is not possible as the MAPI commands are outside of Delphi and the mapi.pas unit is only a wrapper for these functions.
Can anybody help???
Code snippet for current email sending is below:
procedure SendMailDialog(Recip, Subject, Body, Attach : string; ShowDialog : boolean);
mapiMsg : TMapiMessage;
smapiRecip : TMapiRecipDesc;
mapiFileDetail : TMapiFileDesc;
AFile : String;
FillChar(mapiMsg, SizeOf(mapiMsg), 0);
FillChar(smapiRecip, SizeOf(smapiRecip), 0);
FillChar(mapiFileDetail, SizeOf(mapiFileDetail), 0);
smapiRecip.ulRecipClass := MAPI_TO;
smapiRecip.lpszName := '';
smapiRecip.lpszAddress := PChar(Recip);
mapiFileDetail.lpszPathName := PChar(Attach);
AFile := ExtractFilename(Attach);
mapiFileDetail.lpszFileName := PChar(AFile);
mapiMsg.lpszSubject := PChar(Subject);
mapiMsg.lpszNoteText := PChar(Body);
mapiMsg.nRecipCount := 1;
mapiMsg.lpRecips := @smapiRecip;
mapiMsg.nFileCount := 1;
mapiMsg.lpFiles := @mapiFileDetail;
if ShowDialog then
MapiSendMail(0, 0, mapiMsg, MAPI_LOGON_UI+MAPI_DIALOG, 0)
MapiSendMail(0, 0, mapiMsg, 0, 0);