This is what I used, setup my server to send emails with the updated (and former) IP using my gmail account installing postfix from this link. Running Ubuntu 22.04 ARM.
First run this command to save your current IP into a file
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' > ~/myip
The following will now be saved into a *.sh file which you can have cron call as often as needed
# retrieve last saved IP address
NOWIPADDR=$( cat ~/myip )
# check current IP and save in temp
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' > ~/myiptemp
GETIPADDR=$( cat ~/myiptemp )
check if there have been changes
if [ $NOWIPADDR == $GETIPADDR ]
then
# if there were no changes do nothing
echo "No change in IP."
else
# if there were changes, save new IP and send out email informing of such
OLDIP=$NOWIPADDR
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//' > ~/myip
NOWIPADDR=$( cat ~/myip )
echo "IP has changed."
echo "Your IP has changed from $OLDIP to $NOWIPADDR" | mail -s "IP has Changed on Server" youremail@gmail.com
fi
lastly, delete the temp ipfile
rm ~/myiptemp