I have a problem I can't explain - unless it's a configuration problem:
On an AMD64 Ubuntu 22.04 installation I can run a simple sendmail script successfully from Python, but it fails on an Orange Pi Ubuntu 22.04 installation. The errors are as follows:
STARTTLS extension not supported by server.
Traceback (most recent call last):
File "/root/python_sendmail.py", line 34, in <module>
server.quit()
File "/usr/lib/python3.10/smtplib.py", line 1004, in quit
res = self.docmd("quit")
File "/usr/lib/python3.10/smtplib.py", line 432, in docmd
return self.getreply()
File "/usr/lib/python3.10/smtplib.py", line 405, in getreply
raise SMTPServerDisconnected("Connection unexpectedly
closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly
closed
The code is as follows:
# Sending mail with Python
import smtplib, ssl
smtp_server = "smtp.gmail.com"
port = 587 # For starttls
sender_email = [email protected]"
password = 'xxxxxxxxxxxxxxx'
# Create a secure SSL context
context = ssl.create_default_context()
# Try to log in to server and send email
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo() # Can be omitted
server.starttls(context=context) # Secure the connection
server.ehlo() # Can be omitted
server.login(sender_email, password)
# TODO: Send email here
sender_email = "[email protected]"
receiver_email = "[email protected]"
message = """\
Subject: Hi there
This message is sent from Python."""
# Send email here
server.sendmail(sender_email, receiver_email, message)
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()
I had just reinstalled a freshened Jammy image on the Orange Pi and this script had previously run successfully on the Orange Pi.