Python - smtplib

ralbhat

Disciple
Hey,

I'm trying to use the SMTP protocol via python to make a program so that I can mail every student his own marks only (I'll use an excel file to store marks, and I can't send the entire excel sheet because of privacy reason.. plus this gives me something to productively kill time with while learning someting.. :D)

Anyway.. I'm hitting the following error (I typed this in Windows, IDLE, python 2.6.2)

Code:
>>> from smtplib import *

>>> s = SMTP('localhost',25)

Traceback (most recent call last):

  File "<pyshell#10>", line 1, in <module>

    s = SMTP('localhost',25)

  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

I checked the python sites for this, namely : 10. Brief Tour of the Standard Library &mdash; Python v2.6.4 documentation

It says that : " (Note that the second example needs a mailserver running on localhost.)" Where the second example is essentially starting with the code I've given above.

How do I "Run a mailserver on localhost" ?? Trying out net connectivity from programs for the first time.. :huh:

I googled it, it gave some VERY weird solutions, except one that said use the Internet Information Services (IISadmin) :huh::huh::huh:

No idea how to open this, though...

:huh::huh::huh:
 
Just get a free smtp server, start the server on port 25. You wont get the error once the mail server is started.
 
Suggestion, read more about SMTP. Setting up a mail server that works fine in a real world is quite complicated and involved dns settings and so on.

Hence would suggest that you stick to using google's server, for starter:

http://geekmush.wordpress.com/tag/smtplib/

In addition, generate a mail body using:

http://docs.python.org/library/email

+LT
ralbhat said:
Hey,
I'm trying to use the SMTP protocol via python to make a program so that I can mail every student his own marks only (I'll use an excel file to store marks, and I can't send the entire excel sheet because of privacy reason.. plus this gives me something to productively kill time with while learning someting.. :D)
Anyway.. I'm hitting the following error (I typed this in Windows, IDLE, python 2.6.2)

Code:
>>> from smtplib import *
>>> s = SMTP('localhost',25)

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    s = SMTP('localhost',25)
  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

I checked the python sites for this, namely : 10. Brief Tour of the Standard Library &mdash; Python v2.6.4 documentation
It says that : " (Note that the second example needs a mailserver running on localhost.)" Where the second example is essentially starting with the code I've given above.

How do I "Run a mailserver on localhost" ?? Trying out net connectivity from programs for the first time.. :huh:
I googled it, it gave some VERY weird solutions, except one that said use the Internet Information Services (IISadmin) :huh::huh::huh:
No idea how to open this, though...
:huh::huh::huh:
 
Awesome guide by Sam Howard.. Thanks!
I'll contact my tech admin to find out which smtp server to connect to for our college mail..
Thanks!:hap2::hap2::hap2:
 
ralbhat said:
Awesome guide by Sam Howard.. Thanks!
I'll contact my tech admin to find out which smtp server to connect to for our college mail..
Thanks!:hap2::hap2::hap2:

Yeah, if thats too much headache you can always use gmail with reply to set to your college's email address.

+LT
 
Unless you want to code, .. for very simple things you can also use a utility called Blat (google for it). It's a command-line SMTP mailer. You just need to point it to an SMTP server and provide data as a command line switch to it.
 
Back
Top