I can’t take credit for most of this, but modified it slightly to include both network and public IP addresses.
With a Gmail address, you’ll need to allow access for less-secure apps at https://myaccount.google.com. No idea whether you can make it work with 2FA.
Put the script somewhere (
home/pi/scripts/?) and call from
/etc/rc.local with a
sleep 30 or similar command so you’re sure it boots up before trying to send.
See https://gist.github.com/johnantoni/8199088 and citations therein for the original concept.