0

I'm running Rasbian Buster and use Msmtp to send emails from the command line and it works just fine.

When I try to send emails using Python it fails miserably, I've tried various python examples from the net, e.g.

# Sending Email Alerts via Zoho
#
#
import smtplib

server = smtplib.SMTP_SSL('smtp.zoho.com',port=465) #server for sending the email

server.ehlo() # simple starting of the connection
server.login('test_email@zoho.com','pwd_12345') # login credentials and password

msg = """From:test_email@zoho.com
Subject: Test Email \n
To: recipient_email@gmail.com \n"""
# This is where the email content goes. It could be information about the error, time of day, where in the script, etc.

server.sendmail('test_email@zoho.com','recipient_email@gmail.com',msg) # this is where the email is sent to the recipient

server.quit() # exit the connection

... but I unfortunately I always get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.7/smtplib.py", line 387, in getreply
    line = self.file.readline(_MAXLINE + 1)
  File "/usr/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/test_email_python_06.py", line 6, in <module>
    server = smtplib.SMTP('smtpauths.bluewin.ch',port=465) #server for sending the email
  File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.7/smtplib.py", line 338, in connect
    (code, msg) = self.getreply()
  File "/usr/lib/python3.7/smtplib.py", line 391, in getreply
    + str(e))
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 104] Connection reset by peer

As a newbee any hint would be appreciated.

Thanks!

deekee
  • 41
  • 7
  • 3
    We cannot answer with out the code you are using. Imagine you were in our position, and you had the answer to what ever it is you are trying to ask. How, based upon what you have shown, would someone with such knowledge *easily* be able to figure out they could help you? – Krupip Aug 08 '19 at 19:33
  • I've put in more details, hope that helps! – deekee Aug 09 '19 at 17:27
  • Okay, good, I don't have enough expertise in this domain to answer this question, but from the error, perhaps this question is relevant (https://stackoverflow.com/questions/1434451/what-does-connection-reset-by-peer-mean)? It could mean that the peer didn't exist and respond. Are you sure those emails exist? – Krupip Aug 09 '19 at 17:33
  • I can successfully sent email using the command line using msmtp but not with python... – deekee Aug 10 '19 at 17:33

1 Answers1

0

This issue has been solved!

My ISP uses SSL on port 465 and my command line email client MSMTP works just great using that.

As I was so desperate, so that I startet to play around and just use port 25 and "Bingo" the sending of emails works now just fine, the funny part is that my ISP suggest to use port 465.

deekee
  • 41
  • 7