A
A
Alexander Bondarenko2021-12-21 12:01:38
Python
Alexander Bondarenko, 2021-12-21 12:01:38

How to connect to your smtp server?

How can I connect to my smtp server via python?
From the server itself I can send a message

cat ~/test_message | s-nail -s 'Hi my friend' -r [email protected] [email protected]

import smtplib
# set up the SMTP server
from email.mime.multipart import MIMEMultipart

s = smtplib.SMTP(host='mailer.mymailer.xyz', port=25)
msg = MIMEMultipart()  # create a message

# setup the parameters of the message
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = "This is TEST"


# send the message via the server set up earlier.
s.send_message(msg)

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

Server response
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      -
tcp        0    484 myip:22       myip:62440       ESTABLISHED -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::25                   :::*                    LISTEN      -
tcp6       0      0 :::587                  :::*                    LISTEN      -
[email protected]:~$ telnet domain 25
Trying ip...
Connected to mailer.openfreemail.xyz.
Escape character is '^]'.
Connection closed by foreign host.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bondarenko, 2021-12-22
@bond_1013

You need to allow access from any ip in the postfix configuration
networks = 0.0.0.0/0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question