terrychou / iVim

A vim port to iOS.
598 stars 35 forks source link

python smtplib module error #228

Open RunningUtes opened 2 years ago

RunningUtes commented 2 years ago

I was testing the python command in terminal and had an error. Any ideas why the smtp connection would be refused?

Code: testing.py


# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.message import EmailMessage
textfile="output.txt"

# Open the plain text file whose name is in textfile for reading.
with open(textfile) as fp:
    # Create a text/plain message
    msg = EmailMessage()
    msg.set_content(fp.read())

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = f'The contents of {textfile}'
msg['From'] = "me@gmail"
msg['To'] = "you@gmail.com"

# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()

Output:

$ python3 testing.py
Traceback (most recent call last) :
File "testing.py" , line 21, in <module>
s = smtplib.SMTP("localhost')
File
"/private/var/containers/Bundle/Application/9E5C376C-698B-4598-A428-CB9F2CFDBBD9/iVim.app/python/lib/python37.zip/smtplib.py"
, line 251, in init File
"/private/var/containers/Bundle/Application/9E5C376C-698B-4598-A428-CB9F2CFDBBD9/iVim.app/python/lib/python37.zip/smtplib.py'
, line 336, in connect File
"/private/var/containers/Bundle/Application/9E5C376C-698B-4598-A428-CB9F2CFDBBD9/iVim.app/python/lib/python37.zip/smtplib.py
line 307, in get socket File
"/private/var/containers/Bundle/Application/9E5C376C-698B-4598-A428-CB9F2CFDBBD9/iVim.app/python/lib/python37.zip/socket.py
line 727, in create connection File
"/private/var/containers/Bundle/Application/9E5C376C-698B-4598-A428-CB9F2CFDBBD9/iVim.app/python/lib/python37.zip/socket.py"
, line 716, in create_connection
ConnectionRefusedError: [Errno 61] Connection refused
sedm0784 commented 2 years ago

I've never used this module, but it looks like you're connecting to the server localhost, i.e. the iPhone or iPad you're running Vim on. This is not an SMTP server, and so it rejects your attempt to connect to it.

You likely need to enter the address of an actual SMTP server into your call to smtplib.SMTP().