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.
@ECHO OFF
SET email=email@domain.com
SET from=email_from@domain.com
SET emailserver=localhostSET url=http://automation.whatismyip.com/n09230945.asp
SET out=out.txt
SET oldipfile=oldipfile.txtIF 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=%%aECHO.
ECHO The IP address is %ip%.
ECHO Checking last known IP…
ECHO.TYPE %oldipfile% | FIND /i “%ip%” > nul
IF “%ERRORLEVEL%”==”0” ECHO The Ip address is unchanged. && GOTO :eofECHO The IP address has changed. The old IP was:
TYPE %oldipfile%
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.>>mail.txt
echo The new IP address is: %ip% >>mail.txtVMailer.exe mail.txt %emailserver% %email% %from%
del mail.txt
4 comments
Skip to comment form
good site! thanks!
wonderful post.Never knew this, regards for letting me know.
there are many of the articles over internet but this one seems to be taking most of the time. i loved reading it
Is it alright to put part of this on my blog if I submit a reference to this web site?