简体   繁体   中英

Unable to send e-mail using python

I'm running Buster and use SMTP 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, eg

# 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

As a newbee any hint would be appreciated.

Thanks!

This could be a server/firewall configuration issue vs a programming issue. You need to verify that you can send an e-mail through the same server to the same destination via other means from the same device.

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 email notifications work now just fine, the funny part is that my ISP suggest to use port 465.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM