Send email with python from localhost

36 views Asked by At

I was using my gmail account to send email from a python script on OSX 10.11, but recently Google has forbidden "Less Secure App" to access its accounts.

So I'm looking for alternatives and I'm trying out this code but it returns this error:
ConnectionRefusedError: [Errno 61] Connection refused

Here it is:

import smtplib
from email.mime.text import MIMEText

content = "Some content"

message = MIMEText(content)
message['Subject'] = "Some text"
message['From'] = "localhost"
message['To'] = "[email protected]"

with smtplib.SMTP(local_hostname="localhost") as connection:
   connection.connect()
   connection.send_message(message)
   print("ok")
0

There are 0 answers