You host your own mailserver (and the provider even lets you), but the external IP address of your DSL/Cable connection is dynamic. So after a few days suddenly you realise there is no connection to the mailserver, and all the mail is bounced back to the senders. Sure makes for a quiet weekend, but not what you intended with this setup.
If you are somehow unable or unwilling to use Dynamic DNS setups, you can use the script below to periodically lookup the external IP address and send it via email, on the internal side of the mailserver ofcourse, to you if it has changed.
This batch script uses wget.exe and VMailer.exe, you can download both from the downloads section. Automate this script with the Windows Task Scheduler. Make sure to put this script on the actual mailserver so it can actually send the email to you internally. Options that need changing are marked in red.
IF NOT EXIST wget.exe ECHO wget.exe is missing. && GOTO :eof
IF NOT EXIST VMailer.exe ECHO VMailer.exe is missing. && GOTO :eof
IF NOT EXIST %oldipfile% ECHO 0.0.0.0 > %oldipfile%
wget.exe -q -O %out% %url%
FOR /f “tokens=1” %%a IN (%out%) DO SET ip=%%a
ECHO The IP address is %ip%.
ECHO Checking last known IP…
TYPE %oldipfile% | FIND /i “%ip%” > nul
IF “%ERRORLEVEL%”==”0” ECHO The Ip address is unchanged. && GOTO :eof
ECHO The IP address has changed. The old IP was:
ECHO The new IP address is mailed to %email%
ECHO %ip% > %oldipfile%
echo To: %email% >mail.txt
echo From: %from% >>mail.txt
echo Subject: External IP changed! >>mail.txt
echo The new IP address is: %ip% >>mail.txt
VMailer.exe mail.txt %emailserver% %email% %from%