Hi,
I have a internet connection at home. I have installed Python2.6.1 on my laptop in C:\Python26 directory. I have written a script named "TestUtil_SendMail.py" and my intension is to send a mail to the given mail id.

But when am running the script I am getting an error: "[Errno 10061] No connection could be made because the target machine actively refused it". Kindly help me resolve this issue.

TestUtil_SendMail.py:
import smtplib

print "EMAIL UTILITY!!!!!!!!!!!!!!!!!"
SERVER = "localhost"

FROM = "xyz@gmail.com"
TO = ["xyz@gmail.com"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()

print "Mail has been sent... Thanks"

--------------------------------------------------------------------

But while running I am getting the following Error:

>>>
EMAIL UTILITY!!!!!!!!!!!!!!!!!
Traceback (most recent call last):
File "C:/Python26/TestUtil_SendMail.py", line 25, in <module>
server = smtplib.SMTP(SERVER)
File "C:\Python26\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python26\lib\smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python26\lib\smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python26\lib\socket.py", line 512, in create_connection
raise error, msg
error: [Errno 10061] No connection could be made because the target machine actively refused it
>>>

------------------------------------------------------------------------------

Thanks,
Shakila.

Does your laptop also have an open mail server listening on the default port? smptlib provides methods to connect to an smtp mail server, but if your laptop is not currently running one, then you cannot send mail to it.

No, I do not have any mail server listening in my laptop. Actually I woulld like to develop a small python utility which should automatically send mail to the given to address. I will be using this utility when I am in office or at home. So when I am in office I have a lotus notes client running in my system.

Could you please guide me on how to proceed. Do you want me to install any open mail server? If yes, please guide me how to do that.

Thanks,
Shakila.

By the way, Thanks a lot for your reply.

I've never set up a mail server. I suggest google.com

If you have mc Afee there is chance that it can block the port that SMTP uses.

Hi there, check this out, by the way the code that i explain in there it only works for gmail and googlemail, i think.
Also check this, and give us some feed back to the email address reffered.

Dan08.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.