I tried to send e-mail as NT service but i could not send it. the
Mapilogon function fails to logon in NT service.
But It works well as an Standalone application.
here is my code for only sending mail.....
MapiFileDesc
file={0,MAPI_OLE_STATIC,0,"D:\\MSDN.doc","MSDN.doc",".Doc"};
MapiRecipDesc recipient ={0, MAPI_TO,"NT Service test mail",email,0,
NULL};
MapiMessage message ={0,(char *)Name,"NT Service testl" , NULL,NULL ,
NULL , 0 , NULL , 1 , &recipient , 1 , &file};
LHANDLE lhSession;
HMODULE hMAPILib;
hMAPILib = LoadLibrary("MAPI32.DLL");
lpfnMAPILogon =(LPMAPILOGON)GetProcAddress(hMAPILib, "MAPILogon");
lpfnMAPISendMail =(LPMAPISENDMAIL)GetProcAddress(hMAPILib,
"MAPISendMail");
lpfnMAPILogoff =(LPMAPILOGOFF)GetProcAddress(hMAPILib, "MAPILogoff");
ULONG ln;
ln=(*lpfnMAPILogon)(0, "SB","sb", MAPI_NEW_SESSION , 0,&lhSession);
if(ln==SUCCESS_SUCCESS)
MessageBox(NULL,"logon","NT Service",MB_OK);
else
MessageBox(NULL,"not logon","NT Service",MB_OK);
(*lpfnMAPISendMail)(lhSession, 0, &message, 0, 0);
(*lpfnMAPILogoff)(lhSession, 0, 0, 0);
MessageBox(NULL,"Message sent","sent",MB_OK);
FreeLibrary(hMAPILib);
When i run as NT service the Messagebox is displayed which shows "not
logon".
But it works well as standalone application..
please help me in this regard.
I am a fresher and joined in an company as a developer in VC++.
please help me ...
Looking forward to reply from you..