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

Docker: Commonly Used Commands

Repeat to remember Remember to repeat

Powershell: Test-NetConnection

PS C:\Users\tuyen> get-help Test-NetConnection NAME     Test-NetConnection SYNTAX     Test-NetConnection [[-ComputerName] <string>] [-TraceRoute] [-Hops <int>] [-InformationLevel {Quiet |     Detailed}]  [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] [-CommonTCPPort] {HTTP | RDP | SMB | WINRM}     [-InformationLevel {Quiet | Detailed}]  [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] -Port <int> [-InformationLevel {Quiet | Detailed}]     [<CommonParameters>]     Test-NetConnection [[-ComputerName] <string>] -DiagnoseRouting [-ConstrainSourceAddress <string>]     [-ConstrainInterface <uint32>] [-InformationLevel {Quiet | Detailed}]  [<CommonParameters>] ALIASES     TNC REMARKS     Get-Help cannot find the Help files fo...

Windows 10: Install SuSE Linux Enterprise - SLES

With Microsoft-Windows-Subsystem-Linux feature enabled, we can install Linux distributions on Windows 10.