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"
$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