0

I want to send a simple text message to the user from local smtp server. When i am using the following code i am getting the following error

#!/usr/bin/python
import smtplib
receivers = ['to@todomain.com']
message = "hello"
Subject: "SMTP e-mail test
This is a test e-mail message."
try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)         
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"

i am getting the following error:

[WinError 10061] No connection could be made because the target machine actively refused it

How to resolve this error.

userD1989
  • 47
  • 1
  • 7
  • Question duplicate -https://stackoverflow.com/questions/37960035/python-email-errno-10061-no-connection-could-be-made-because-the-target-machi – Ananth.P Feb 28 '20 at 12:10
  • @Ananth.P I tried that but i dont want to use any from address just have to send a simple text – userD1989 Feb 28 '20 at 12:30

1 Answers1

0

If this happens always, it literally means that the port is blocked by your firewall. (What port are you listening on?) you have to open port 25 if you want send mails from your machine. Of course also a mail server/service should be running.

Radi
  • 46
  • 5