0

I'm doing a script for send a mail of my company, the host it's a IP so I'm trying to connect on this way (also tryied anothers) but nothing....

This is my code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import commands
import sys
import smtplib          # Librería envío de reporte

#Datos de envio

correo_emisor = "mail"
correo_receptor = "mail"
msg = "Correo de prueba"
psw_correo = "pwd"

#Conexion servidor de correo

try:
        print "Conectando..."
        servidor_correo = smtplib.SMTP("217.28.130.90", port=587)
        #servidor_correo = SMTP()
        #servidor_correo.connect("217.28.130.90", 587)
        servidor_correo.ehlo()
        servidor_correo.starttls()
        servidor_correo.ehlo()
        print "Conexion exitosa a servidor de correo..."
        #Datos para envio de correo
        servidor_correo.login(correo_emisor,psw_correo)
except  smtplib.SMTPConnectError as e:
        print (str(e))
        sys.exit()

#Contenido de correo

asunto = "Correo de prueba"
servidor_correo.strip(asunto)

try:
        servidor_correo.sendmail(correo_emisor, correo_receptor, msg)
except  smtplib.SMTPException:
        print "El correo no se pudo enviar"
        servidor_correo.close()
        sys.exit()

And I have the next error:

[informix@informix_vm_01 pruebas_correo]$ ./Test.py
Conectando...
Traceback (most recent call last):
  File "./Test.py", line 24, in <module>
    servidor_correo = smtplib.SMTP("217.28.130.90:587")
  File "/usr/lib64/python2.7/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib64/python2.7/smtplib.py", line 315, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib64/python2.7/smtplib.py", line 290, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 110] Connection timed out

I already tried different ways to fix it but nothing!

Urkidy
  • 97
  • 9
  • Maybe the connection actually times out? I. e. it's a network problem or connections to that server on that port are dropped? – blubberdiblub May 03 '17 at 15:59
  • @blubberdiblub I don't think that's the problem because actually I have another script on php and it works! – Urkidy May 03 '17 at 16:04
  • With exactly the same IP address and exactly the same port number? And running on the same host? (A server can also drop a connection based on where it comes from.) – blubberdiblub May 03 '17 at 16:06
  • @blubberdiblub Yes: `public $MessageDate = ''; public $Host = '217.28.130.90'; public $Port = 587; public $Helo = ''; public $SMTPSecure = 'tls';` – Urkidy May 03 '17 at 16:24
  • Well, you need to show us the error message that actually corresponds to your code. In the error message you posted one can clearly see a different `smtplib.SMTP()` call than in the code snippet above. – blubberdiblub May 03 '17 at 16:38

0 Answers0