[Tutor] sending mails from python
Python
python at venix.com
Sat Oct 21 14:14:04 CEST 2006
On Sat, 2006-10-21 at 12:45 +0200, euoar wrote:
> I'm trying to learn how to send e-mails with python. But I always become
> this error: socket.error: (110, 'Connection timed out').
It sounds like you were unable to connect to the mail server. That
could be due to a large number of network issues and is probably not a
Python bug.
from a terminal/cmd window try
telnet smtpserver 25
That will connect to the smtpserver on the proper port (and works for
most operating systems). I expect that to fail. Your Python code will
not work until you can actually make a connection.
Here's what I get trying to reach a non-existent smtpserver:
telnet 10.10.10.10 25
Trying 10.10.10.10...
telnet: connect to address 10.10.10.10: Connection timed out
telnet: Unable to connect to remote host: Connection timed out
> Is there
> something bad in the code? Does anyone knows what could be wrong? I'm
> using python from linux, and have no proxy...
>
> The code that I use is this (of course, filling with my persona data the
> " "):
>
> import smtplib
>
> smtpserver = 'my smtp server goes here'
> AUTHREQUIRED = 1
> smtpuser = 'my user name'
> smtppass = 'my password'
>
> RECIPIENTS = ['the recipients']
> SENDER = 'my mail'
> mssg = "una prueba desde python"
>
> session = smtplib.SMTP(smtpserver)
> if AUTHREQUIRED:
> session.login(smtpuser, smtppass)
> smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
>
> if smtpresult:
> errstr = ""
> for recip in smtpresult.keys():
> errstr = """Could not delivery mail to: %s
>
> Server said: %s
> %s
>
> %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
> raise smtplib.SMTPException, errstr
>
>
>
> Thank you for your help
>
>
>
>
>
>
> ______________________________________________
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp
More information about the Tutor
mailing list