Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Dec : Re: invoke email client
| Subject: | Re: invoke email client |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Mon, 1 Jan 2007 12:57:26 |
"Peter" <peace3977@yahoo.com> wrote in message
news:459865b4$1@newsgroups.borland.com...
> Well, I put a call to MapiSendMail in my app, it always gets an
error
> MAPI_E_FAILURE
You are not using it correctly. Try this code instead:
uses
Mapi;
procedure TfrmMain.btnEmailClick(Sender: TObject);
var
Session : LHANDLE;
Orig : TMapiRecipDesc;
Recip : PMapiRecipDesc;
Msg : TMapiMessage;
Res : Integer;
begin
ZeroMemory(@Msg, SizeOf(Msg));
ZeroMemory(@Orig, SizeOf(Orig));
// if you do not want to specify a MAPI profile explicitially,
you can retreive the default one from the Registry:
//
// NT+: HKCU\Software\Microsoft\Windows
NT\CurrentVersion\Windows Messaging Subsystem\Profiles
// 9x/ME: HCKU\Software\Microsoft\Windows Messaging
Subsystem\Profiles
//
// "DefaultProfile" (REG_SZ) = "the profile name"
Res := MAPILogon(Application.Handle, 'Mapi Profile here', '',
MAPI_LOGON_UI, 0, @Session);
if Res = SUCCESS_SUCCESS then
begin
Res := MAPIResolveName(Session, Application.Handle,
'sysadmin@pfksystems.com', 0, 0, Recip);
if Res = SUCCESS_SUCCESS then
begin
Recip^.ulRecipClass := MAPI_TO;
Orig.ulRecipClass := MAPI_ORIG;
Orig.lpszName := 'Peter';
Orig.lpszAddress := 'peter@pfksystems.com';
Msg.lpszSubject := 'Message subject here';
Msg.lpszNoteText := 'Message text here';
Msg.lpOriginator := @Orig;
Msg.nRecipCount := 1;
Msg.lpRecips := Recip;
Res := MapiSendMail(Session, Application.Handle, Msg,
MAPI_LOGON_UI, 0);
MAPIFreeBuffer(@Recip);
end;
MAPILogoff(Session, Application.Handle, 0, 0);
end;
sb.SimpleText := 'Result: ' + IntToStr(Res);
end;
Gambit