Skip to main content

hmailserver: Notes from the field

hmailserver is one of free open source mail servers running on Microsoft Windows operating system.

Logging setttings

Enable logging consumes a lot of disk space if our mail server is busy all day, but it surely helps us find out what really happened.


Powershell script scanning awstats log file to remove email addresses that no longer exist


# Default hmailserver's log folder
$Dir="C:\Program Files (x86)\hMailServer\Logs"

# Email pattern
$regex = '\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b'
$today = (Get-Date).ToString("yyyy-MM-dd")

# Scan hmailserver's awstats log file for 550 return code
Select-String -Pattern '\tSMTP\t\?\t550\t0$' $Dir\hmailserver_awstats.log  | Out-File $Dir\hmailserver_awstats-$today.txt -width 200 -Append


if($?) {
select-string -Path $Dir\hmailserver_awstats-$today.txt -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $Dir\hmailserver_awstats-$today-filtered.txt
}



# Remove duplicate lines
if($?) {
Get-Content $Dir\hmailserver_awstats-$today-filtered.log.txt | sort | Get-Unique > $Dir\hmailserver_awstats-$today-unique.txt
}
# End of script

Popular posts from this blog

Powershell: Install IIS

Run Powershell as Administrator, then run the command below to install IIS. Install-WindowsFeature Web-WebServer Check after installing Get-WindowsFeature *Web*

Microsoft Azure Repos

Azure Repos Documentation

Microsoft Windows Server 2012 R2 Standard Evaluation Product Key

Microsoft Windows Server 2012 R2 Standard Evaluation D2N9P-3P6X9-2R39C-7RTCD-MDVJX DBGBW-NPF86-BJVTX-K3WKJ-MTB6V