-1

So basically, I am trying to create a program which repeatedly sends the same email from one account to another in 24hr intervals. (I will have files linked to it, the data of which will change day to day, but I am going to figure that out at another time) So, before creating the intervals, I figured that I would get the email to send first. I got the code written, and there aren't any errors in the actual code, but when I run it, the terminal returns the message "ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it"

for now, I am just trying to get the email to send, and I have looked all over for a solution, but I can't seem to figure it out. It has also come to my attention that I need to use something other than a 'local host' as the mail server, so I would also appreciate any answers as to what to use instead of 'local host'. Thank you for any help that you can give. Here is my complete code at the moment:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
port_number = 587
msg = MIMEMultipart()
msg['From'] = 'Example@gmail.com'
msg['to'] = 'Example@gmail.com'
msg['Subject'] = 'My test mail '
message = 'test, test, testing'
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('localhost', port_number)
mailserver.login("Example@gmail.com", "My Gmail app password")
mailserver.sendmail('Example@gmail.com', 'Example@gmail.com', msg.as_string())
mailserver.quit()
  • 5
    Are you actually using `smtplib.SMTP('localhost'` in your code? That will only work if there's a local SMTP server, or in your Proton Mail case, a Proton Mail Bridge installed. Proton doesn't provide publicly accessible SMTP endpoint. – Martheen Aug 14 '23 at 23:33
  • Try looking at [Receive and send emails in python](https://stackoverflow.com/questions/348392/receive-and-send-emails-in-python). – Alias Cartellano Aug 15 '23 at 19:51

0 Answers0