0

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'] = "my.name@gmail.com"

with smtplib.SMTP(local_hostname="localhost") as connection:
   connection.connect()
   connection.send_message(message)
   print("ok")
Neuran
  • 137
  • 10
  • Are you running an SMTP server on your localhost? – Barmar Jul 09 '22 at 16:22
  • if I run on terminal "telnet localhost 25" it says "Connection refused". How to start the smtp server then? (by the way, I have XAMPP installed) – Neuran Jul 09 '22 at 18:21
  • 2
    An SMTP server of your own is unlikely to work if you want to send email to the public Internet. If you just need local email, any simple SMTP server should work, but how to configure it is off-topic for Stack Overflow. – tripleee Jul 09 '22 at 19:01
  • 1
    To amplify what @triplee says, most organizations will not accept mail from random machines, because they're more likely to be spambots. If you can't send through Gmail, use your ISP's SMTP relay. – Barmar Jul 09 '22 at 21:29

0 Answers0