0

I want to send emails out, originating from my Debian computer. I do NOT want the emails to originate from my gmail account, like in most Python smtplib examples.

I called my ISP regarding port 25, and they told me to use (port 587) or (port 465 with SSL). Both ports have the same result, the email gets generated but not delivered. If I try to use smtplib.SMTP_SSL in python with port 465, I get this error:

  File "emailer.py", line 32, in <module>
    smtp = smtplib.SMTP_SSL("localhost", 465)
  File "/usr/lib/python2.7/smtplib.py", line 792, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 798, in _get_socket
    new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
  File "/usr/lib/python2.7/ssl.py", line 891, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 566, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake
    self._sslobj.do_handshake()
socket.error: [Errno 104] Connection reset by peer

My Python emailer code:

to_addr = "me@gmail.com"
from_addr = ""
body_text = "auto email test"
message = MIMEText(body_text)
message["Subject"] = "subject"
message["From"] = from_addr
message["To"] = to_addr
message["Return-Path"] = "<>"
message["Auto-Submitted"] = "auto-generated"
smtp = smtplib.SMTP("localhost", 587)
try:
    #smtp.starttls()
    print("sending email")
    smtp.sendmail(from_addr, [to_addr], message.as_string())  #body_text)
    print("sent email")
except Exception, em:
    print("ERROR: " + str(em) )
except SMTPException, em:
    print("ERROR: " + str(em) )
smtp.quit()

This code runs without any errors. When I check the mail queue, the message is sitting there not going anywhere.

root@lappy:/home/user/raid# mailq
 0m   482 1aLBNr-0005Fj-Ui <test@lappy.home>
          me@gmail.com

This type of message appears in /var/log/exim4/mainlog as the message is attempted to be sent, but eventually times out.

2016-01-18 10:06:20 1aLBNr-0005Fj-Ui <= test@lappy.home H=localhost (lappy.home) [::1] P=esmtp S=482
2016-01-18 10:08:27 1aLBNr-0005Fj-Ui gmail-smtp-in.l.google.com [74.125.203.26] Connection timed out
2016-01-18 10:10:34 1aLBNr-0005Fj-Ui alt2.gmail-smtp-in.l.google.com [64.233.160.26] Connection timed out
2016-01-18 10:12:42 1aLBNr-0005Fj-Ui alt3.gmail-smtp-in.l.google.com [74.125.207.26] Connection timed out
2016-01-18 10:12:43 1aLBNr-0005Fj-Ui == me@gmail.com R=dnslookup T=remote_smtp defer (110): Connection timed out

exim prints this to the main log. Here you can see is configured to listen on port 587:

2016-01-18 09:14:03 exim 4.84 daemon started: pid=10234, -q30m, listening for SMTP on [127.0.0.1]:587 [::1]:587

I have this line in /etc/default/exim4:

SMTPLISTENEROPTIONS='-oX 587 -oP /var/run/exim4/exim.pid'

I currently don't have TLS activated in exim (/etc/exim4/exim4.conf.template):

#####################################################
### main/03_exim4-config_tlsoptions
#####################################################
#tls_on_connect_ports=465
### main/03_exim4-config_tlsoptions
#################################
  • The python script is irrelevant; this would happen regardless of how the email was generated. The important thing here would be to know how exim is configured. – Jenny D Jan 18 '16 at 15:31
  • Default configuration, except the SMTPLISTENEROPTIONS line I mentioned. – paperduck Jan 18 '16 at 15:35
  • Your listener options are also irrelevant. The issue occurs when exim is sending the email out to gmail, not when exim is receiving it from your perl script. You can't expect people here to go looking for a default config that might or might not match your default. (Also, why have you set the return address to <>? That should only be used for bounce messages!) – Jenny D Jan 18 '16 at 15:38
  • What configuration settings are you concerned about in particular? – paperduck Jan 18 '16 at 15:45
  • Since the problem is with sending mail, the ones regarding sending mail would be interesting. Also, since your ISP informed you that you should be using port 587/465 instead of port 25, the default exim configuration is highly unlikely to work for you, since it defaults to using the standard SMTP port for outgoing mail. – Jenny D Jan 18 '16 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.