Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Script to mark all mail as read
PostPosted: 2011-12-14 22:58 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
Hi, can you please help me implementing a simple script to mark all received mail as read?

I've created a rule with Action->Run Function: OnAcceptMessage (should I have used OnDeliverMessage instead??)

and my vbs looks like this:

Code:
'   Sub OnClientConnect(oClient)
'   End Sub

Sub OnAcceptMessage(oClient, oMessage)
   oMessage.Flag(1) = True
End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

'  Sub OnDeliverMessage(oMessage)

' End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oMessage, sRemoteUID)
'   End Sub


Surprise surprise it doesn't work. :)

Now obviously I've never done any scripting in my life and I could not find any newb-friendly guide here on your site. From the help file I believe at least my rule is defined properly but I'm not sure.

So would somebody be so kind and create this (I believe) very simple script for me?

Many thanks!


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 02:10 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
OK

All of the built in subs work automatically. You don't need to call them from rules.
http://www.hmailserver.com/documentatio ... ce_scripts
(remember to enable scripts and then to re-load the script in the GUI)

I'd probably use on deliver message, unless you only want this work for some accounts, then I'd call it something else and THEN call it from a rule....

And then you need to save the message
You were close!!

Try like this
Code:
'   Sub OnClientConnect(oClient)
'   End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

Sub OnDeliverMessage(oMessage)
   oMessage.Flag(1) = True
        oMessage.save
End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oMessage, sRemoteUID)
'   End Sub

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 03:14 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
OK thanks! I deleted the rule and used your script. Then reloaded the scripts. But it doesn't work. The new messages I receive are kept unread.

I should probably mention that I'm using IMAP in Hmailserver and the way my emails are actually "received" is I use a rule in Outlook to copy a received message from my exchange account into the hmail's IMAP mailbox. Then the message "arrives" in my hmailserver account but it's not processed by the script, apparently.

Should this special type of delivery make any difference and is there a way to check what might be wrong?


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 03:31 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
telnet wrote:
Should this special type of delivery make any difference and is there a way to check what might be wrong?

Yes that makes a difference

The only way that I can see would be to mark ALL messages as read, every day, or every hour using a scheduled task
What version of Outlook?
Can you add a condition to your rule to mark the message as read as part of the copy?

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 12:14 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
mattg wrote:
telnet wrote:
Should this special type of delivery make any difference and is there a way to check what might be wrong?

Yes that makes a difference

The only way that I can see would be to mark ALL messages as read, every day, or every hour using a scheduled task
What version of Outlook?
Can you add a condition to your rule to mark the message as read as part of the copy?


Yes the task sounds like a good idea. How do I accomplish this?

Outlook is 2010 and the rule can only mark as read the message in the exchange inbox (and copy it as such to the IMAP inbox) which is not what I need. I need it to stay unread in exchange but read in hmailserver.


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 15:12 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
here is a starting point

viewtopic.php?f=9&t=17019&p=100540&hilit=flag#p100540

You would need to iterate through all accounts and folders...

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 16:01 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
I have just one account and the only folder I need to be marked as read periodically is the IMAP Inbox.

So this should work?

Code:
set obFolders = obAccount.IMAPFolders
dim obFolder = obFolders.ItemByName(obFolder.Name) -- should I put INBOX in the brackets here??
dim obMessages = obFolder.Messages

for d=0 to msgcount
set msg2 = obMessages .Item(d)
msg2.Flag(1) = true  -- like this?
msg2.Save
next


Then set up a scheduled task in Windows to run this script?

Thanks!


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 16:22 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
Something like this (not tested - please test on a backup machine first if possible)

Change the password at the top
Code:
Option Explicit

const g_sAdminPassword = "secret"  'CHANGE ME

dim oApp, obMessages, obMessage
set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", g_sAdminPassword)

set obMessages = oApp.Domains.item(0).Accounts.item(0).obFolders.ItemByName("Inbox").Messages

for d=0 to obMessages.count -1
   set obMessage = obMessages.Item(d)
   obMessage.Flag(2) = false
   obMessage.Save
next

Basically save this as a file 'something.vbs', and then IF it works as planned, create a scheduled task to run this every whatever timeframe

As the number of messages increases, this script will take more and more time to run.
You could change the way that you get these messages into hMailserver rather than the Outlook rule, you could use hMailserver's external account feature, and then you could mark as read as they are downloaded (as per previous posts in this thread).

In fact if you used hmailserver's external account to download these messages, you may not even need to log onto the hMailserver account except to check that they are being downloaded. If you don't log onto the account, then you won't notice the 'un-read' status of the messages. Just a thought.

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 16:48 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
The exchange server does not support POP3 which is the only protocol available for external accounts in HMS as far as I can see. So this is not an option.

Anyway, I've tried the script and get an error on this line:

Quote:
Option Explicit


Line: 30
Char: 1
Error: Expected statement


You've been of great help so far, hope you can solve this last step of the puzzle? :)


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-15 17:28 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
Uups sorry, here's the full script and error result. The previous error was due to my poor commenting skills. :P

Code:
'   Sub OnClientConnect(oClient)
'   End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

' Sub OnDeliverMessage(oMessage)
'   oMessage.Flag(1) = True
'        oMessage.save
' End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oMessage, sRemoteUID)
'   End Sub

Option Explicit

const g_sAdminPassword = "deleted"  'CHANGE ME

dim oApp, obMessages, obMessage
set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", g_sAdminPassword)

set obMessages = oApp.Domains.item(0).Accounts.item(0).obFolders.ItemByName("Inbox").Messages

for d=0 to obMessages.count -1
   set obMessage = obMessages.Item(d)
   obMessage.Flag(2) = false
   obMessage.Save
next



Description: Object doesn't support this property or method: 'Domains.item(...).Accounts.item(...).obFolders' - Line 38


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-16 02:13 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
Ok sorry. Try this
Code:
'   Sub OnClientConnect(oClient)
'   End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

' Sub OnDeliverMessage(oMessage)
'   oMessage.Flag(1) = True
'        oMessage.save
' End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oMessage, sRemoteUID)
'   End Sub

Option Explicit

const g_sAdminPassword = "secret"  'CHANGE ME

dim oApp, obMessages, obMessage
set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", g_sAdminPassword)

set obMessages = oApp.Domains.item(0).Accounts.item(0).IMAPFolders.ItemByName("Inbox").Messages

for d=0 to obMessages.count -1
   set obMessage = obMessages.Item(d)
   obMessage.Flag(2) = false
   obMessage.Save
next

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-16 02:46 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
I'm getting another error now:


Line: 40
Variable is undefined: 'd'


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-16 03:10 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
Ok Try this - #3 :)
Code:
'   Sub OnClientConnect(oClient)
'   End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

' Sub OnDeliverMessage(oMessage)
'   oMessage.Flag(1) = True
'        oMessage.save
' End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oMessage, sRemoteUID)
'   End Sub

Option Explicit

const g_sAdminPassword = "secret"  'CHANGE ME

dim oApp, obMessages, obMessage, d
set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", g_sAdminPassword)

set obMessages = oApp.Domains.item(0).Accounts.item(0).IMAPFolders.ItemByName("Inbox").Messages

for d=0 to obMessages.count -1
   set obMessage = obMessages.Item(d)
   obMessage.Flag(2) = false
   obMessage.Save
next

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: Script to mark all mail as read
PostPosted: 2011-12-16 10:41 
New user
New user

Joined: 2011-12-14 22:48
Posts: 8
I can now run the script but checking the folder in outlook, it doesn't mark the unread messages I have as read. Hmmm....


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group