Add the Python equivalent of Powershell's Test-NetConnection to your script and sleep for a few seconds and retest.
if (!(Test-NetConnection www.microsoft.com -CommonTCPPort HTTP).TcpTestSucceeded) {
start-sleep -seconds 60
}
If the network is not available, the script will just keep trying (sleeping) and when the PC gets back online, it will continue to the next statement and send the email.
I am not familiar with Python, but I found this with a simple search.