Automatic POP3 fetch with delay between each download

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
User avatar
Normal user
Normal user
Posts: 42
Joined: 2018-11-19 19:15

Automatic POP3 fetch with delay between each download

Post by derelvis » 2019-08-23 13:05

As I recently had some trouble with handshake errors during download of external accounts via POP3, I managed to get rid of the problem by using a vbs script included in a task scheduler task. In my case the problem occurred because many pop3 fetches started at the same time and then ended up in about 50% of "TCPConnection - TLS/SSL handshake failed" errors. So I looked for a way to get a little delay between the trigger of the external downloads. The script is based on a version from jimimaseye, thanks for the support!
For reference: ... =7&t=34245

It loops through all enabled external accounts in all active accounts of all active domains, starts the donwload and adds a configurable delay between each fetch.

Adjust the CONFIG part for your needs (Admin username, Admin Password, verbose mode, delay)
verbose=1 shows some more information for debugging when started in a cmd box
delay=1000 means setting a delay of 1 sec between every fetch

Either start it in a cmd prompt by hand or create a task scheduler task like this:
Program/Script: C:\Windows\System32\cscript.exe - Arguments: "<pathto>\Automatic_POP3_fetch.vbs"
Trigger for task: every x minutes

THE CODE (click 'SELECT ALL' and copy/paste):

Code: Select all

'  Script forces download of all enabled external accounts for all active accounts of every active domain
'  Use in task scheduler: Program/Script: C:\Windows\System32\cscript.exe - Arguments: "<pathto>\Automatic_POP3_fetch.vbs"

Option Explicit

' #### CONFIG START ####
	Const HMSADMINUSER = "Administrator"	' Admin username
	Const HMSADMINPWD = ""			' Admin password
	verbose = 0 				' set to 1 for some debugging output
	delay = 1000				' delay between fetches in ms
' #### CONFIG END ####

' Objects
Dim oApp, oDomain, oAccount, oExtAccount

' Numeric
Dim x, y, z, i, verbose, delay

	Set oApp = CreateObject("hMailServer.Application")

	If verbose = 1 then wscript.echo(" Domain.Count: " & oApp.Domains.Count)
	For x = 1 To oApp.Domains.Count
		Set oDomain = oApp.Domains.Item(x-1)
		If oDomain.Active Then
			If verbose = 1 then wscript.echo(" - Domain " & x & ": " & oDomain.Name)
			If verbose = 1 then wscript.echo("  - Accounts.Count: " & oDomain.Accounts.Count)
			For y = 1 to oDomain.Accounts.Count
				Set oAccount = oDomain.Accounts.Item(y-1)
				If Then
					If verbose = 1 then wscript.echo("  - Address " & y & ": " & oAccount.Address)
					If verbose = 1 then wscript.echo("   - FetchAccounts.Count: " & oAccount.FetchAccounts.Count)
						For z = 1 To oAccount.FetchAccounts.Count
							Set oExtAccount = oAccount.FetchAccounts.Item(z-1)
							If oExtAccount.Enabled Then
								If verbose = 1 then wscript.echo("    - FetchAccount " & z & ": " & oExtAccount.Name)
								wscript.echo("      Download " & i & " - Account: " & oExtAccount.Name & " --> Ext. Account: " & oAccount.address)
								wscript.sleep delay 'wait for x sec until fetching next account
								i = i + 1
							End if 
				End if
		End if

HMS 5.7.0-B2484 (x64) (DB version 5700) - MySQL 8.0.15
ClamWin0.99.4 + Clamd service - SpamAssassin
Windows Server 2012 - 64Bit

Post Reply