How to Stop and Start hMailServer using COM API?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

How to Stop and Start hMailServer using COM API?

Post by bazporter » 2006-08-27 14:32

I would like to be able to stop and start hMailServer using the COM API. Reason: I like to re-start spamd on a regular basis so that any new rules, and new bayes information is synced (eg from salearn), and if I restart spamd whilst hMailServer is trying to use it I'm going to get message errors.

Currently I achieve this using a batch file which uses net stop hMailServer and net start hMailServer. The problem with this is that all the statistics get reset every time.

Looking at the COM API docs there is a property of ServerState which may or may not be able to help with this, however when I try and use it to see what it gives me I get an error "You do not have access to this propert / method".

Here is the code I am trying:

Code: Select all

dim obApp
set obApp = createObject("hMailServer.Application")

msgBox "hMailServer state " & obApp.ServerState
Please can anybody tell me what I am doing wrong, and if it is possible to control the run state of hMailServer this way?

Many thanks.

--
Regards
Barry

random
Normal user
Normal user
Posts: 108
Joined: 2006-07-16 09:51
Location: Germany

Post by random » 2006-08-27 14:43

Hi,

maybe that will work:

Code: Select all

dim obApp
set obApp = createObject("hMailServer.Application")

obApp.Stop 'Stops hMailServer
'
' do anything
'
obApp.Start 'Starts hMailServer
It doesn't terminate the hMailServer-Process, but no Mail will be delivered. It's like you press the "Stop" or "Start"-Button in hMailAdmin.

cu
random

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-08-27 14:45

Why do you need to restart hMailServer service to synch bayes information?

It's not possible to stop / start the hMailServer service using the COM API, because the COM API is provided by the hMailServer service. The only way to stop the service is to use NET command as you do today

Using the COM API (Application.Start and Application.Stop) , it's possible to start and stop the TCP/IP severs within hMailServer - not the service itself. However, doing this doesn't reload any settings.

bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

Post by bazporter » 2006-08-27 14:51

Hi Martin and random,

Thanks for the pointer to Application.start and stop, that's just what I need.

I was only restarting the hmail service for synching the bayes information so that hmail would not try and use spamc/spamd to check a mail for spam while the spamd service is down, which could cause message errors.

Many thanks.

--
Regards
Barry

User avatar
martin
Developer
Developer
Posts: 6834
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-08-27 15:00

Alright.
And another thing. You need to call

Call Application.Authenticate("administrator", "your-main-hmailserver-password")

If you don't do this, you'll get the "Access denied" message you posted in your first message.

bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

Post by bazporter » 2006-08-27 15:23

Thanks Martin, I was just looking at DecryptBlowfish.vbs to see how that did it.

--
Regards
Barry

Post Reply