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..

Re: Plz help me to correct my code to send E-mail as NT service . by Maxim

Maxim
Mon Aug 07 23:59:10 CDT 2006

Try using CDO-NTS objects instead of MAPI.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

"kanthasamy M" <kanthasamy.tech.sup@gmail.com> wrote in message
news:1154926132.548577.324580@m79g2000cwm.googlegroups.com...
> 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..
>


Re: Plz help me to correct my code to send E-mail as NT service . by Tim

Tim
Tue Aug 08 01:09:38 CDT 2006

"kanthasamy M" <kanthasamy.tech.sup@gmail.com> wrote:
>
>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.

Right. MAPI sends e-mail using the current e-mail application of the
currently logged-on user. Services do not have access to the currently
logged-in user. They run in a separate environment.

You could try using SMTP, or you can investigate using impersonation.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.