A
A
Alexander Bondarenko2021-12-06 17:11:10
Python
Alexander Bondarenko, 2021-12-06 17:11:10

How to fix ConnectionRefusedError: [WinError 10061] smtplib?

I'm trying to start my smtp server and send a message, I get an error:

ConnectionRefusedError: [WinError 10061] Подключение не установлено, т.к. конечный компьютер отверг запрос на подключение

Server:
import smtpd
import asyncore


class CustomSMTPServer(smtpd.SMTPServer):

    def process_message(self, peer, mailfrom, rcpttos, data):
        print('Receiving message from:', peer)
        print('Message addressed from:', mailfrom)
        print('Message addressed to  :', rcpttos)
        print('Message length        :', len(data))
        return


server = CustomSMTPServer(('127.0.0.1', 1025), None)

asyncore.loop()


Customer:
import smtplib
import email.utils
from email.mime.text import MIMEText

# Create the message
msg = MIMEText('This is the body of the message.')
msg['To'] = email.utils.formataddr(('Recipient', '[email protected]'))
msg['From'] = email.utils.formataddr(('Author', '[email protected]'))
msg['Subject'] = 'Simple test message'

server = smtplib.SMTP('127.0.0.1', 1025)
server.set_debuglevel(True) # show communication with the server
server.connect()
server.login('', '')
try:
    server.sendmail('[email protected]', ['[email protected]'], msg.as_string())
finally:
    server.quit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-12-07
@bond_1013

https://www.cyberforum.ru/python/thread2262439.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question