def sendEmail():
testnetEmail = checkNetwork("https://google.fi")
if testnetEmail:
print("Network check OK. Sending error email...")
consoleInsertText("Network check OK. Sending error email..." + 'n')
email = 'zzzz@gmail.com'
password = 'xxxxx'
send_to_email = 'yyyyy@gmail.com'
msg = MIMEMultipart()
msg['From'] = 'ArduMower ERROR STATE'
msg['To'] = send_to_email
msg['Subject'] = 'Errors and console output'
msg.attach(MIMEText("Error counters:n" + "Charger: {}nBattery: {}nMotor Left: {}nMotor Right: {}nMotor Mow: {}nMow Sense: {}nOdometry Left: {}nOdometry Right: {}nPerimeter Timeout: {}nPerimeter Tracking: {}nIMU Communication: {}nIMU Calibration: {}nIMU Tilt: {}nRTC Communication: {}nRTC Data: {}nGPS Communication: {}nGPS Data: {}nRobot Stuck: {}nEEPROM Data: {}nn".format(mymower.ErrCharger, mymower.ErrBattery, mymower.ErrMotorLeft, mymower.ErrMotorRight, mymower.ErrMotorMow, mymower.ErrMowSense, mymower.ErrOdoLeft, mymower.ErrOdoRight, mymower.ErrPeriTout, mymower.ErrTracking, mymower.ErrImuComm, mymower.ErrImuCalib, mymower.ErrImuTilt, mymower.ErrRtcComm, mymower.ErrRtcData, mymower.ErrGpsComm, mymower.ErrGpsData, mymower.ErrStuck, mymower.ErrEepromData) + "Console output:n" + txtConsoleRecu.get('1.0','end'), 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to_email, text)
server.quit()
print("Error email sent!")
consoleInsertText("Error email sent!" + 'n')
return True
else:
print("Network connection problem. Email not sended!")
consoleInsertText("Network connection problem. Email not sended!" + 'n')
return False