Score:0

sendmail not working in Python on Orange Pi

cn flag

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.

user78290 avatar
cn flag
Both installations are Python 3.10.6
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.