How to create a reoccurring email every 1 hour (for testing connectivity)

dabomb

2[H]4U
Joined
Apr 12, 2001
Messages
2,393
I would like to send out an email every hour from an external account to make sure that our mail server is receiving external messages. If I do not receive this email on my exchange account on my blackberry, it would alert me that there is a problem with the server.

Is there any program or free email service that would provide this functionality?
 
bmail is a command line e-mail generator.

you can use vbscript and CDO to send an e-mail as well.

then just run it as a scheduled task to repeat every hour.
 
There are services that do this. But i dont' think they are free.

Do you use an external spam filter?
 
There are services that do this. But i dont' think they are free.

Do you use an external spam filter?


No internal spam filter (GFI) that runs on the smtp server. Exchange is on a separate box. Reason behind me wanting this is the anti-spam services hung, smtp got hung, and we did not process external emails from 6pm yesterday through 9:15am this morning (I come in at 9.) I had been communicating with other internal users during this timeframe and never realized the problem.
 
I use GFI as well. I have a whole slew of scripts running to test connectivity. I'll post them in a few.
This one monitors the normal troublespots for GFI Mail Essentials / Security. When it stops processing mail, they usually queue up here.
Code:
Option Explicit
Dim watchedPaths, filesys, folder, files, path, maxcount, pagecount, pagers, notify

maxcount = 150
pagecount = 1000

pagers = "[email protected]"
notify = "[email protected]"


watchedPaths = array("C:\inetpub\mailroot\queue", "c:\inetpub\mailroot\badmail", _
	"c:\Program Files\GFI\ContentSecurity\MailSecurity\FailedMails", _
	"c:\Program Files\GFI\MailEssentials\FailedMails")

Set filesys = CreateObject("Scripting.FileSystemObject")

For Each path in watchedpaths
	Set folder = filesys.GetFolder(path)
	Set files = folder.files
	If files.count > pagecount Then
		sendemail pagers, path
		sendemail notify, path
	ElseIf files.count > maxcount Then
		'msgbox "sending email"
		sendemail notify, path
	End If
Next

sub sendemail(recip, alertpath)
	Dim objEmail
	Set objEmail = CreateObject("CDO.Message")
	objEmail.From = "[email protected]"
	objEmail.To = recip
	objEmail.Subject = "GFI Folder Monitor Alert" 
	objEmail.Textbody = alertpath + " has " + files.count + " files in it.  This " + _
		"can indicate a failure in mail processing.  Check services."
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.0.0.5" 
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	objEmail.Configuration.Fields.Update
	objEmail.Send
End sub

I need to find the one I use to monitor the services, but I also use external monitoring - http://www.bello-monitors-the.net to establish an SMTP session every hour and page me via an external address if it can't connect.

edit: here's the service monitoring one
Code:
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep, colServicesToCheck, serviceStatus
strComputer = "."
intSleep = 4000

colServicesToCheck =  array("csecmlhost", "GFIMETRXSVC", "gfiasmlhost", "GFIScanS", "msecmlhost", "GFIScanM", "GFI MailEssentials Legacy Attendant Service")

For Each strService in colServicesToCheck
'  wscript.echo "checking " & strService
  serviceStatus = serviceStatus & kickService(strService)
Next

If serviceStatus <> "" Then
  sendemail "[email protected]", serviceStatus
End If

Function kickService(strName)
'On Error Resume Next
' NB strService is case sensitive.
strService = " '" & strName & "' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " and State = 'Stopped'")
kickService = ""
If colListOfServices.Count <> 0 Then
  For Each objService in colListOfServices
    objService.StartService()
    kickService = kickService & objService.DisplayName & " was stopped.  I kicked it and now it's started. " & vbCRLF
  Next
End If
End Function

sub sendemail(recip, alertpath)
	Dim objEmail
	Set objEmail = CreateObject("CDO.Message")
	objEmail.From = "[email protected]"
	objEmail.To = recip
	objEmail.Subject = "GFI Services Kickstart" 
	objEmail.Textbody = "These servies (and the services they depend on) were kickstarted.  " & vbCRLF & vbCRLF & alertPath
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "10.0.0.5" 
	objEmail.Configuration.Fields.Item _
		("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	objEmail.Configuration.Fields.Update
	objEmail.Send
End sub

If you're set on testing full mailflow, just modify the mail function to connect to your GFI mail gateway and send mail through there. Just use a from address without an SPF record and it should go through fine (or whitelist the from address).
 
Last edited:
nice scripts, i use gfi mail essentials 2012 myself

[EDIT] Ya old thread, dam google searches!
 
Last edited:
Prtg. I use this to monitor 4 sites. My 2 remote sites monitor my main site so it's a ring - type setup. I like to know shits busted first.
 
prtg i have and it works, but can you set it to test if an email is going through or not..

The issue i have is even though i have a 30Mb limit on emails for my Exchange system, Kayako system will hang when we get a customer who send's the same 2-5Mb file 100 times, just never downloads the first file then eventually gets stuck when the cron job runs to check the accounts again

So in this case i know the server is up and working and emails are being delivered, but they are not making it through to our Support team.
 
Are you looking to monitor STMP availability to the public internet or verify the entire SMTP from receipt through delivery?

If the former, and it's just one, setup an account with MXtoolbox.com and have it use your 1 freebie to monitor SMTP. Of course this method just makes sure your SMTP server is still alive and accepts commands but doesn't actually send an email.

Otherwise, use one of the tools above :)
 
got Pingdom, but the issue with all of these systems is they do not track the mail flow from one point to another they merely check is a site is up / active / responding.

Nagios will monitor a response if pop3 /imap or such is responding, but once that email leaves the mail server...it cant do anything. PRTG as well can monitor the response of pop3 and other protocols.

The issue here for me is Kayako really and why it gets stuck with multiple 2-5Mb emails and parsing them, so until Kayako looks into it to fix it, i merely wanted to send an email every hours to see if it makes it from point A to point B.
 
I use Blat with Mini Relay to email myself logs a couple times a day. I have compiled Autohotkey scripts that check a file exists, if it does then it runs Mini Relay, then Blat sends me an email with the file attached, then Autohotkey kills Mini Relay and the task is done. Scheduled to run twice a day. You could easily use this to send yourself emails, I'd even give you the scripts with notes.
 
You could use procmail to homebrew something, procmail will let you setup rules, so basically, have a script send mail (this can be done with the "mail" command in Linux) and on the receiver have that account have a procmail rule to do something when that mail arrives. It could be as simple as updating a text file with the current unix time stamp.

Then have your monitoring software monitor the value of the current time stamp minus that time stamp. If the number gets larger than 3660 (1 hour and 1 minute) then trigger an alarm.

I use this method to monitor the polling for all my alarm points. If the arduino or the script monitoring the arduino gets hung up, that value will increase and trigger an alarm that the polling is off. My hvac control app does something similar, each cycle it updates the temperature values in a text file as well as the time stamp of that update. So if that app gets hung up or crashes I get an alert.

This is all Linux based though, not sure how it would be done if it's a Windows environment. I imagine it would not be as easy.
 
Back
Top